Path: blob/master/src/java.base/share/classes/javax/crypto/spec/PSource.java
41159 views
/*1* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.crypto.spec;2627/**28* This class specifies the source for encoding input P in OAEP Padding,29* as defined in the30* <a href="https://tools.ietf.org/rfc/rfc8017.txt">PKCS#1 v2.2</a> standard.31* <pre>32* PSourceAlgorithm ::= AlgorithmIdentifier {33* {PKCS1PSourceAlgorithms}34* }35* </pre>36* where37* <pre>38* PKCS1PSourceAlgorithms ALGORITHM-IDENTIFIER ::= {39* { OID id-pSpecified PARAMETERS EncodingParameters },40* ... -- Allows for future expansion --41* }42* EncodingParameters ::= OCTET STRING(SIZE(0..MAX))43* </pre>44* @author Valerie Peng45*46* @since 1.547*/48public class PSource {4950private String pSrcName;5152/**53* Constructs a source of the encoding input P for OAEP54* padding as defined in the PKCS #1 standard using the55* specified PSource algorithm.56* @param pSrcName the algorithm for the source of the57* encoding input P.58* @exception NullPointerException if <code>pSrcName</code>59* is null.60*/61protected PSource(String pSrcName) {62if (pSrcName == null) {63throw new NullPointerException("pSource algorithm is null");64}65this.pSrcName = pSrcName;66}67/**68* Returns the PSource algorithm name.69*70* @return the PSource algorithm name.71*/72public String getAlgorithm() {73return pSrcName;74}7576/**77* This class is used to explicitly specify the value for78* encoding input P in OAEP Padding.79*80* @since 1.581*/82public static final class PSpecified extends PSource {8384private byte[] p = new byte[0];8586/**87* The encoding input P whose value equals byte[0].88*/89public static final PSpecified DEFAULT = new PSpecified(new byte[0]);9091/**92* Constructs the source explicitly with the specified93* value <code>p</code> as the encoding input P.94* Note:95* @param p the value of the encoding input. The contents96* of the array are copied to protect against subsequent97* modification.98* @exception NullPointerException if <code>p</code> is null.99*/100public PSpecified(byte[] p) {101super("PSpecified");102this.p = p.clone();103}104/**105* Returns the value of encoding input P.106* @return the value of encoding input P. A new array is107* returned each time this method is called.108*/109public byte[] getValue() {110return (p.length==0? p: p.clone());111}112}113}114115116