blob: 3d3098158a68abf8a48d9461d7edc3baa4e8c4b2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/*
* Copyright (C) 2024, Thomas Wolf <twolf@apache.org> and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
* https://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package org.eclipse.jgit.gpg.bc.internal.keys;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.x9.ECNamedCurveTable;
/**
* Some OIDs apparently unknown to Bouncy Castle.
*/
public final class ObjectIds {
/**
* Legacy OID for ed25519 used in OpenPGP.
*/
public static final ASN1ObjectIdentifier OID_OPENPGP_ED25519 =
new ASN1ObjectIdentifier("1.3.6.1.4.1.11591.15.1"); //$NON-NLS-1$
/**
* OID for ed25519 according to RFC 8410.
*/
public static final ASN1ObjectIdentifier OID_RFC8410_ED25519 =
new ASN1ObjectIdentifier("1.3.101.112"); //$NON-NLS-1$
/**
* Legacy OID for curve25519 used in OpenPGP.
*/
public static final ASN1ObjectIdentifier OID_OPENPGP_CURVE25519 =
ECNamedCurveTable.getOID("curve25519"); //$NON-NLS-1$
// This is 1.3.6.1.4.1.3029.1.5.1
/**
* OID for curve25519 according to RFC 8410.
*/
public static final ASN1ObjectIdentifier OID_RFC8410_CURVE25519 = new ASN1ObjectIdentifier(
"1.3.101.110"); //$NON-NLS-1$
/**
* Determines whether the given {@code oid} denoted ed25519.
*
* @param oid
* to test
* @return {@code true} if it is ed25519, {@code false} otherwise
*/
public static boolean isEd25519(ASN1ObjectIdentifier oid) {
return OID_OPENPGP_ED25519.equals(oid)
|| OID_RFC8410_ED25519.equals(oid);
}
/**
* Determines whether the given {@code oid} denoted curve25519.
*
* @param oid
* to test
* @return {@code true} if it is curve25519, {@code false} otherwise
*/
public static boolean isCurve25519(ASN1ObjectIdentifier oid) {
return OID_RFC8410_CURVE25519.equals(oid)
|| OID_OPENPGP_CURVE25519.equals(oid);
}
/**
* Retrieves an OID by name.
*
* @param name
* to get the OID for
* @return the OID, or {@code null} if unknown.
*/
public static ASN1ObjectIdentifier getByName(String name) {
if (name != null) {
switch (name) {
case "Ed25519": //$NON-NLS-1$
return OID_OPENPGP_ED25519;
case "Curve25519": //$NON-NLS-1$
return OID_OPENPGP_CURVE25519;
default:
break;
}
}
return null;
}
/**
* Checks whether two OIDs denote the same algorithm.
*
* @param oid1
* First OID to test
* @param oid2
* Second OID to test
* @return {@code true} if the two OIDs match, {@code false} otherwise
*/
public static boolean match(ASN1ObjectIdentifier oid1,
ASN1ObjectIdentifier oid2) {
if (isEd25519(oid1)) {
return isEd25519(oid2);
}
if (isCurve25519(oid1)) {
return isCurve25519(oid2);
}
return oid1 != null && oid1.equals(oid2);
}
}
|