Skip to content

Commit 9123961

Browse files
committedOct 26, 2023
8318096: Introduce AsymmetricKey interface with a getParams method
Reviewed-by: darcy, mullan, ascarpino
1 parent 4a142c3 commit 9123961

File tree

18 files changed

+313
-20
lines changed

18 files changed

+313
-20
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
package java.security;
27+
28+
import java.security.spec.AlgorithmParameterSpec;
29+
30+
/**
31+
* An asymmetric key, which can be either a public key or a private key.
32+
* This interface contains methods that are common to either a public key or
33+
* a private key.
34+
*
35+
* @since 22
36+
*/
37+
public interface AsymmetricKey extends Key {
38+
/**
39+
* Returns the parameters associated with this key.
40+
* The parameters are optional and may be either
41+
* explicitly specified or implicitly created during
42+
* key pair generation.
43+
*
44+
* @implSpec
45+
* The default implementation returns {@code null}.
46+
*
47+
* @return the associated parameters, may be {@code null}
48+
*/
49+
default AlgorithmParameterSpec getParams() {
50+
return null;
51+
}
52+
}

‎src/java.base/share/classes/java/security/PrivateKey.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -57,7 +57,7 @@
5757
* @since 1.1
5858
*/
5959

60-
public interface PrivateKey extends Key, javax.security.auth.Destroyable {
60+
public interface PrivateKey extends AsymmetricKey, javax.security.auth.Destroyable {
6161

6262
// Declare serialVersionUID to be compatible with JDK1.1
6363
/**

‎src/java.base/share/classes/java/security/PublicKey.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -44,7 +44,7 @@
4444
*
4545
*/
4646

47-
public interface PublicKey extends Key {
47+
public interface PublicKey extends AsymmetricKey {
4848
// Declare serialVersionUID to be compatible with JDK1.1
4949
/**
5050
* The class fingerprint that is set to indicate serialization

‎src/java.base/share/classes/java/security/interfaces/DSAParams.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,7 @@
2626
package java.security.interfaces;
2727

2828
import java.math.BigInteger;
29+
import java.security.spec.AlgorithmParameterSpec;
2930

3031
/**
3132
* Interface to a DSA-specific set of key parameters, which defines a
@@ -40,7 +41,7 @@
4041
* @author Josh Bloch
4142
* @since 1.1
4243
*/
43-
public interface DSAParams {
44+
public interface DSAParams extends AlgorithmParameterSpec {
4445

4546
/**
4647
* Returns the prime, {@code p}.

‎src/java.base/share/classes/java/security/interfaces/DSAPrivateKey.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -62,4 +62,18 @@ public interface DSAPrivateKey extends DSAKey, java.security.PrivateKey {
6262
* @return the value of the private key, {@code x}.
6363
*/
6464
BigInteger getX();
65+
66+
/**
67+
* {@inheritDoc java.security.AsymmetricKey}
68+
*
69+
* @implSpec
70+
* The default implementation returns {@code null}.
71+
*
72+
* @return {@inheritDoc java.security.AsymmetricKey}
73+
* @since 22
74+
*/
75+
@Override
76+
default DSAParams getParams() {
77+
return null;
78+
}
6579
}

‎src/java.base/share/classes/java/security/interfaces/DSAPublicKey.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -62,4 +62,18 @@ public interface DSAPublicKey extends DSAKey, java.security.PublicKey {
6262
* @return the value of the public key, {@code y}.
6363
*/
6464
BigInteger getY();
65+
66+
/**
67+
* {@inheritDoc java.security.AsymmetricKey}
68+
*
69+
* @implSpec
70+
* The default implementation returns {@code null}.
71+
*
72+
* @return {@inheritDoc java.security.AsymmetricKey}
73+
* @since 22
74+
*/
75+
@Override
76+
default DSAParams getParams() {
77+
return null;
78+
}
6579
}

‎src/java.base/share/classes/java/security/interfaces/ECPrivateKey.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,7 @@
2626

2727
import java.math.BigInteger;
2828
import java.security.PrivateKey;
29+
import java.security.spec.ECParameterSpec;
2930

3031
/**
3132
* The interface to an elliptic curve (EC) private key.
@@ -56,4 +57,18 @@ public interface ECPrivateKey extends PrivateKey, ECKey {
5657
* @return the private value S.
5758
*/
5859
BigInteger getS();
60+
61+
/**
62+
* {@inheritDoc java.security.AsymmetricKey}
63+
*
64+
* @implSpec
65+
* The default implementation returns {@code null}.
66+
*
67+
* @return {@inheritDoc java.security.AsymmetricKey}
68+
* @since 22
69+
*/
70+
@Override
71+
default ECParameterSpec getParams() {
72+
return null;
73+
}
5974
}

‎src/java.base/share/classes/java/security/interfaces/ECPublicKey.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
2525
package java.security.interfaces;
2626

2727
import java.security.PublicKey;
28+
import java.security.spec.ECParameterSpec;
2829
import java.security.spec.ECPoint;
2930

3031
/**
@@ -58,4 +59,18 @@ public interface ECPublicKey extends PublicKey, ECKey {
5859
* @return the public point W.
5960
*/
6061
ECPoint getW();
62+
63+
/**
64+
* {@inheritDoc java.security.AsymmetricKey}
65+
*
66+
* @implSpec
67+
* The default implementation returns {@code null}.
68+
*
69+
* @return {@inheritDoc java.security.AsymmetricKey}
70+
* @since 22
71+
*/
72+
@Override
73+
default ECParameterSpec getParams() {
74+
return null;
75+
}
6176
}

‎src/java.base/share/classes/java/security/interfaces/EdECPrivateKey.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
2525
package java.security.interfaces;
2626

2727
import java.security.PrivateKey;
28+
import java.security.spec.NamedParameterSpec;
2829
import java.util.Optional;
2930

3031
/**
@@ -52,4 +53,18 @@ public interface EdECPrivateKey extends EdECKey, PrivateKey {
5253
* If the key is not available, then an empty {@code Optional}.
5354
*/
5455
Optional<byte[]> getBytes();
56+
57+
/**
58+
* {@inheritDoc java.security.AsymmetricKey}
59+
*
60+
* @implSpec
61+
* The default implementation returns {@code null}.
62+
*
63+
* @return {@inheritDoc java.security.AsymmetricKey}
64+
* @since 22
65+
*/
66+
@Override
67+
default NamedParameterSpec getParams() {
68+
return null;
69+
}
5570
}

‎src/java.base/share/classes/java/security/interfaces/EdECPublicKey.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,7 @@
2626

2727
import java.security.PublicKey;
2828
import java.security.spec.EdECPoint;
29+
import java.security.spec.NamedParameterSpec;
2930

3031
/**
3132
* An interface for an elliptic curve public key as defined by
@@ -47,4 +48,18 @@ public interface EdECPublicKey extends EdECKey, PublicKey {
4748
* @return the {@code EdECPoint} representing the public key.
4849
*/
4950
EdECPoint getPoint();
51+
52+
/**
53+
* {@inheritDoc java.security.AsymmetricKey}
54+
*
55+
* @implSpec
56+
* The default implementation returns {@code null}.
57+
*
58+
* @return {@inheritDoc java.security.AsymmetricKey}
59+
* @since 22
60+
*/
61+
@Override
62+
default NamedParameterSpec getParams() {
63+
return null;
64+
}
5065
}

‎src/java.base/share/classes/java/security/interfaces/RSAPrivateKey.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,7 @@
2626
package java.security.interfaces;
2727

2828
import java.math.BigInteger;
29+
import java.security.spec.AlgorithmParameterSpec;
2930

3031
/**
3132
* The interface to an RSA private key.
@@ -59,4 +60,18 @@ public interface RSAPrivateKey extends java.security.PrivateKey, RSAKey
5960
* @return the private exponent
6061
*/
6162
BigInteger getPrivateExponent();
63+
64+
/**
65+
* {@inheritDoc java.security.AsymmetricKey}
66+
*
67+
* @implSpec
68+
* The default implementation returns {@code null}.
69+
*
70+
* @return {@inheritDoc java.security.AsymmetricKey}
71+
* @since 22
72+
*/
73+
@Override
74+
default AlgorithmParameterSpec getParams() {
75+
return null;
76+
}
6277
}

‎src/java.base/share/classes/java/security/interfaces/RSAPublicKey.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,7 @@
2626
package java.security.interfaces;
2727

2828
import java.math.BigInteger;
29+
import java.security.spec.AlgorithmParameterSpec;
2930

3031
/**
3132
* The interface to an RSA public key.
@@ -56,4 +57,18 @@ public interface RSAPublicKey extends java.security.PublicKey, RSAKey
5657
* @return the public exponent
5758
*/
5859
BigInteger getPublicExponent();
60+
61+
/**
62+
* {@inheritDoc java.security.AsymmetricKey}
63+
*
64+
* @implSpec
65+
* The default implementation returns {@code null}.
66+
*
67+
* @return {@inheritDoc java.security.AsymmetricKey}
68+
* @since 22
69+
*/
70+
@Override
71+
default AlgorithmParameterSpec getParams() {
72+
return null;
73+
}
5974
}

‎src/java.base/share/classes/java/security/interfaces/XECPrivateKey.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
2525
package java.security.interfaces;
2626

2727
import java.security.PrivateKey;
28+
import java.security.spec.AlgorithmParameterSpec;
2829
import java.util.Optional;
2930

3031
/**
@@ -53,5 +54,19 @@ public interface XECPrivateKey extends XECKey, PrivateKey {
5354
* and the private key is not allowed to leave the crypto boundary).
5455
*/
5556
Optional<byte[]> getScalar();
57+
58+
/**
59+
* {@inheritDoc java.security.AsymmetricKey}
60+
*
61+
* @implSpec
62+
* The default implementation returns {@code null}.
63+
*
64+
* @return {@inheritDoc java.security.AsymmetricKey}
65+
* @since 22
66+
*/
67+
@Override
68+
default AlgorithmParameterSpec getParams() {
69+
return null;
70+
}
5671
}
5772

0 commit comments

Comments
 (0)