src/java.base/share/classes/javax/crypto/spec/PSource.java
author wetmore
Fri, 11 May 2018 15:53:12 -0700
branchJDK-8145252-TLS13-branch
changeset 56542 56aaa6cb3693
parent 47216 71c04702a3d5
permissions -rw-r--r--
Initial TLSv1.3 Implementation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.crypto.spec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * This class specifies the source for encoding input P in OAEP Padding,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * as defined in the
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    31
 * <a href="https://tools.ietf.org/rfc/rfc8017.txt">PKCS#1 v2.2</a> standard.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    32
 * <pre>
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    33
 * PSourceAlgorithm ::= AlgorithmIdentifier {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    34
 *   {PKCS1PSourceAlgorithms}
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    35
 * }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    36
 * </pre>
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    37
 * where
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * PKCS1PSourceAlgorithms    ALGORITHM-IDENTIFIER ::= {
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    40
 *   { OID id-pSpecified PARAMETERS EncodingParameters },
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *   ...  -- Allows for future expansion --
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * }
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    43
 * EncodingParameters ::= OCTET STRING(SIZE(0..MAX))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @author Valerie Peng
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
public class PSource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private String pSrcName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * Constructs a source of the encoding input P for OAEP
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * padding as defined in the PKCS #1 standard using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * specified PSource algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * @param pSrcName the algorithm for the source of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * encoding input P.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * @exception NullPointerException if <code>pSrcName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    protected PSource(String pSrcName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        if (pSrcName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            throw new NullPointerException("pSource algorithm is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        this.pSrcName = pSrcName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Returns the PSource algorithm name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @return the PSource algorithm name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public String getAlgorithm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        return pSrcName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * This class is used to explicitly specify the value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * encoding input P in OAEP Padding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public static final class PSpecified extends PSource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        private byte[] p = new byte[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
         * The encoding input P whose value equals byte[0].
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        public static final PSpecified DEFAULT = new PSpecified(new byte[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
         * Constructs the source explicitly with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
         * value <code>p</code> as the encoding input P.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
         * Note:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
         * @param p the value of the encoding input. The contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
         * of the array are copied to protect against subsequent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
         * modification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
         * @exception NullPointerException if <code>p</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        public PSpecified(byte[] p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            super("PSpecified");
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   103
            this.p = p.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
         * Returns the value of encoding input P.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
         * @return the value of encoding input P. A new array is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
         * returned each time this method is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        public byte[] getValue() {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   111
            return (p.length==0? p: p.clone());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
}