summaryrefslogtreecommitdiffstats
path: root/luni/src/main/java/javax/crypto/spec/PSource.java
blob: f64431680ed85cfd0d961e41058d67e45d9e79d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package javax.crypto.spec;

import libcore.util.EmptyArray;

/**
 * The source of the label <code>L</code> as specified in <a
 * href="http://www.ietf.org/rfc/rfc3447.txt"> PKCS #1</a>.
 */
public class PSource {

    private String pSrcName;

    private PSource() {}

    /**
     * Creates a new <code>PSource</code> instance with the specified source
     * algorithm identifier.
     *
     * @param pSrcName
     *            the source algorithm identifier.
     * @throws NullPointerException
     *             if pSrcName is null.
     */
    protected PSource(String pSrcName) {
        if (pSrcName == null) {
            throw new NullPointerException("pSrcName == null");
        }
        this.pSrcName = pSrcName;
    }

    /**
     * Returns the source algorithm identifier.
     *
     * @return the source algorithm identifier.
     */
    public String getAlgorithm() {
        return pSrcName;
    }

    /**
     * The explicit specification of the parameter <code>P</code> used in the
     * source algorithm.
     */
    public static final class PSpecified extends PSource {

        private final byte[] p;

        /**
         * The instance of <code>PSpecified</code> with the default value
         * <code>byte[0]</code> for <code>P</code>
         */
        public static final PSpecified DEFAULT = new PSpecified();

        private PSpecified() {
            super("PSpecified");
            p = EmptyArray.BYTE;
        }

        /**
         * Creates a new instance of <code>PSpecified</code> with the specified
         * parameter <code>P</code>.
         *
         * @param p
         *            the parameter <code>P</code>.
         * @throws NullPointerException
         *             if <code>p</code> is null.
         */
        public PSpecified(byte[] p) {
            super("PSpecified");
            if (p == null) {
                throw new NullPointerException("p == null");
            }
            //TODO: It is unknown which name should be used!
            //super("");
            this.p = new byte[p.length];
            System.arraycopy(p, 0, this.p, 0, p.length);
        }

        /**
         * Returns a copy of the value of the parameter <code>P</code>.
         *
         * @return a copy of the value of the parameter <code>P</code>
         */
        public byte[] getValue() {
            byte[] result = new byte[p.length];
            System.arraycopy(p, 0, result, 0, p.length);
            return result;
        }
    }
}