8327779: Remove deprecated internal field sun.security.x509.X509Key.key

Reviewed-by: mullan
This commit is contained in:
Eirik Bjørsnøs 2024-03-28 20:00:07 +00:00
parent 341dd57fa1
commit 4eefda9102
2 changed files with 7 additions and 53 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -33,6 +33,7 @@ import java.security.*;
import java.security.interfaces.*;
import java.security.spec.*;
import sun.security.util.BitArray;
import sun.security.util.ECParameters;
import sun.security.util.ECUtil;
@ -59,7 +60,6 @@ public final class ECPublicKeyImpl extends X509Key implements ECPublicKey {
* Construct a key from its components. Used by the
* ECKeyFactory.
*/
@SuppressWarnings("deprecation")
ECPublicKeyImpl(ECPoint w, ECParameterSpec params)
throws InvalidKeyException {
this.w = w;
@ -67,7 +67,8 @@ public final class ECPublicKeyImpl extends X509Key implements ECPublicKey {
// generate the encoding
algid = new AlgorithmId
(AlgorithmId.EC_oid, ECParameters.getAlgorithmParameters(params));
key = ECUtil.encodePoint(w, params.getCurve());
byte[] key = ECUtil.encodePoint(w, params.getCurve());
setKey(new BitArray(key.length * 8, key));
}
/**
@ -92,17 +93,9 @@ public final class ECPublicKeyImpl extends X509Key implements ECPublicKey {
return params;
}
// Internal API to get the encoded point. Currently used by SunPKCS11.
// This may change/go away depending on what we do with the public API.
@SuppressWarnings("deprecation")
public byte[] getEncodedPublicValue() {
return key.clone();
}
/**
* Parse the key. Called by X509Key.
*/
@SuppressWarnings("deprecation")
protected void parseKeyBits() throws InvalidKeyException {
AlgorithmParameters algParams = this.algid.getParameters();
if (algParams == null) {
@ -112,7 +105,7 @@ public final class ECPublicKeyImpl extends X509Key implements ECPublicKey {
try {
params = algParams.getParameterSpec(ECParameterSpec.class);
w = ECUtil.decodePoint(key, params.getCurve());
w = ECUtil.decodePoint(getKey().toByteArray(), params.getCurve());
} catch (IOException | InvalidParameterSpecException e) {
throw new InvalidKeyException("Invalid EC key", e);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -65,24 +65,6 @@ public class X509Key implements PublicKey, DerEncoder {
/* The algorithm information (name, parameters, etc). */
protected AlgorithmId algid;
/**
* The key bytes, without the algorithm information.
* @deprecated Use the BitArray form which does not require keys to
* be byte aligned.
* @see sun.security.x509.X509Key#setKey(BitArray)
* @see sun.security.x509.X509Key#getKey()
*/
@Deprecated
protected byte[] key = null;
/*
* The number of bits unused in the last byte of the key.
* Added to keep the byte[] key form consistent with the BitArray
* form. Can de deleted when byte[] key is deleted.
*/
@Deprecated
private int unusedBits = 0;
/* BitArray form of key */
private transient BitArray bitStringKey = null;
@ -112,15 +94,6 @@ public class X509Key implements PublicKey, DerEncoder {
*/
protected void setKey(BitArray key) {
this.bitStringKey = (BitArray)key.clone();
/*
* Do this to keep the byte array form consistent with
* this. Can delete when byte[] key is deleted.
*/
this.key = key.toByteArray();
int remaining = key.length() % 8;
this.unusedBits =
((remaining == 0) ? 0 : 8 - remaining);
}
/**
@ -128,18 +101,6 @@ public class X509Key implements PublicKey, DerEncoder {
* @return a BitArray containing the key.
*/
protected BitArray getKey() {
/*
* Do this for consistency in case a subclass
* modifies byte[] key directly. Remove when
* byte[] key is deleted.
* Note: the consistency checks fail when the subclass
* modifies a non byte-aligned key (into a byte-aligned key)
* using the deprecated byte[] key field.
*/
this.bitStringKey = new BitArray(
this.key.length * 8 - this.unusedBits,
this.key);
return (BitArray)bitStringKey.clone();
}
@ -331,7 +292,7 @@ public class X509Key implements PublicKey, DerEncoder {
HexDumpEncoder encoder = new HexDumpEncoder();
return "algorithm = " + algid.toString()
+ ", unparsed keybits = \n" + encoder.encodeBuffer(key);
+ ", unparsed keybits = \n" + encoder.encodeBuffer(bitStringKey.toByteArray());
}
/**