Skip to content

Commit

Permalink
Rename helper method for OID comparison
Browse files Browse the repository at this point in the history
This helper method will match against OIDs
for Ed25519, Ed448, X25519 or X448.

Signed-off-by: Rikard Höglund <[email protected]>
  • Loading branch information
rikard-sics committed Apr 22, 2021
1 parent 35eebc1 commit 1f1994e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
7 changes: 2 additions & 5 deletions src/main/java/COSE/ASN1.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,12 @@ private static String tagToString(int tag) {
private static final int IntegerTag = 2;

/**
* Determine if a specific OID is matching one used for ECDH or EdDSA.
* See https://www.iana.org/assignments/cose/cose.xhtml#elliptic-curves
*
* This means it is matching either Ed25519, Ed448, X25519 or X448.
* Determine if a specific OID is matching either Ed25519, Ed448, X25519 or X448.
*
* @param oid the OID to check
* @return if it is matching Ed25519, Ed448, X25519 or X448
*/
public static boolean isEcdhEddsaOid(byte[] oid) {
public static boolean isEdXOid(byte[] oid) {
return Arrays.equals(oid, ASN1.Oid_Ed25519) || Arrays.equals(oid, ASN1.Oid_Ed448)
|| Arrays.equals(oid, ASN1.Oid_X25519) || Arrays.equals(oid, ASN1.Oid_X448);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/COSE/OneKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ else if (Arrays.equals(alg.get(0).value, ASN1.Oid_rsaEncryption)) {

keyMap.Add(KeyKeys.RSA_N.AsCBOR(), n.value);
keyMap.Add(KeyKeys.RSA_E.AsCBOR(), e.value);
} else if (ASN1.isEcdhEddsaOid(alg.get(0).value)) {
} else if (ASN1.isEdXOid(alg.get(0).value)) {
byte[] oid = (byte[]) alg.get(0).value;
if (oid == null)
throw new CoseException("Invalid SPKI structure");
Expand Down Expand Up @@ -186,7 +186,7 @@ else if (Arrays.equals(alg.get(0).value, ASN1.Oid_rsaEncryption)) {
keyMap.Add(KeyKeys.RSA_QI.AsCBOR(), pkdl.get(8).value);

// todo multi prime keys
} else if (ASN1.isEcdhEddsaOid(alg.get(0).value)) {
} else if (ASN1.isEdXOid(alg.get(0).value)) {
byte[] oid = (byte[]) alg.get(0).value;
if (oid == null)
throw new CoseException("Invalid PKCS8 structure");
Expand Down

0 comments on commit 1f1994e

Please sign in to comment.