RFR: 8265372: Simplify PKCS9Attribute [v5]
Weijun Wang
weijun at openjdk.org
Wed Jan 24 18:43:33 UTC 2024
On Fri, 12 Jan 2024 00:17:32 GMT, Ben Perez <duke at openjdk.org> wrote:
>> Refactored PKCS9Attribute to use a hash map instead of multiple arrays. The key for the hash map is an `ObjectIdentifier` and the values are a record `AttributeInfo` that stores the information previously contained in the arrays `PKCS9_VALUE_TAGS`, `VALUE_CLASSES`, and `SINGLE_VALUED`.
>>
>> It seems as though we should be able to get rid of constants such as `EMAIL_ADDRESS_OID` since they aren't heavily used with the hash map approach, but since the values are public it might cause compatibility issues.
>>
>> Another question is how to handle `RSA DSI`, `S/MIME`, `Extended-certificate`, and `Issuer Serial Number` OIDs. The prior version threw an error but in this refactor they are treated as an "unknown OID" and only throw a debug warning. This was addressed in https://bugs.openjdk.org/browse/JDK-8011867 but prior to this refactor the aforementioned OIDs were treated differently than unknown OIDs.
>
> Ben Perez has updated the pull request incrementally with one additional commit since the last revision:
>
> Added comments for new functions
src/java.base/share/classes/sun/security/pkcs/PKCS9Attribute.java line 34:
> 32: import java.util.Arrays;
> 33: import java.util.List;
> 34: import java.util.ArrayList;
Useless imports for `List` and `ArrayList`.
src/java.base/share/classes/sun/security/pkcs/PKCS9Attribute.java line 104:
> 102:
> 103: if (infoMap.put(oid, info) != null) {
> 104: throw new RuntimeException("Duplicate oid: " + oid);
I usually use `AssertionError`. This is a JDK implementation error.
src/java.base/share/classes/sun/security/pkcs/PKCS9Attribute.java line 126:
> 124: /* Simplifies lambda expressions when setting AttributeInfo */
> 125: private static DerOutputStream mkDerStream(DerOutputStream t, DerOutputStream r) {
> 126: return t.write(DerValue.tag_Set, r.toByteArray());
I think there is no need to call `toByteArray`. Just use `r` itself.
src/java.base/share/classes/sun/security/pkcs/PKCS9Attribute.java line 167:
> 165: a -> Arrays.stream(a).map(Throws.unchecked(
> 166: e -> new SignerInfo(e.toDerInputStream()))).toArray(),
> 167: (v,t) -> t.putOrderedSetOf(DerValue.tag_Set, (DerEncoder[]) v),
This is not single valued and the lambda should only take care of an element and not the set. Maybe should be `t.write((DerEncoder) v)`.
src/java.base/share/classes/sun/security/pkcs/PKCS9Attributes.java line 309:
> 307: boolean first = true;
> 308: for (ObjectIdentifier oid : PKCS9Attribute.getOIDs()) {
> 309: if (oid == null) continue;
This should not happen.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/17132#discussion_r1465170461
PR Review Comment: https://git.openjdk.org/jdk/pull/17132#discussion_r1465175997
PR Review Comment: https://git.openjdk.org/jdk/pull/17132#discussion_r1465312830
PR Review Comment: https://git.openjdk.org/jdk/pull/17132#discussion_r1465308164
PR Review Comment: https://git.openjdk.org/jdk/pull/17132#discussion_r1465165815
More information about the security-dev
mailing list