diff options
Diffstat (limited to 'crypto/src/asn1/x509/SubjectKeyIdentifier.cs')
-rw-r--r-- | crypto/src/asn1/x509/SubjectKeyIdentifier.cs | 56 |
1 files changed, 23 insertions, 33 deletions
diff --git a/crypto/src/asn1/x509/SubjectKeyIdentifier.cs b/crypto/src/asn1/x509/SubjectKeyIdentifier.cs index f2e6cc006..bb694681b 100644 --- a/crypto/src/asn1/x509/SubjectKeyIdentifier.cs +++ b/crypto/src/asn1/x509/SubjectKeyIdentifier.cs @@ -15,54 +15,44 @@ namespace Org.BouncyCastle.Asn1.X509 public class SubjectKeyIdentifier : Asn1Encodable { - private readonly byte[] keyIdentifier; - - public static SubjectKeyIdentifier GetInstance( - Asn1TaggedObject obj, - bool explicitly) + public static SubjectKeyIdentifier GetInstance(Asn1TaggedObject obj, bool explicitly) { return GetInstance(Asn1OctetString.GetInstance(obj, explicitly)); } - public static SubjectKeyIdentifier GetInstance( - object obj) + public static SubjectKeyIdentifier GetInstance(object obj) { if (obj is SubjectKeyIdentifier) - { - return (SubjectKeyIdentifier) obj; - } - - if (obj is SubjectPublicKeyInfo) - { - return new SubjectKeyIdentifier((SubjectPublicKeyInfo) obj); - } - - if (obj is Asn1OctetString) - { - return new SubjectKeyIdentifier((Asn1OctetString) obj); - } - - if (obj is X509Extension) - { - return GetInstance(X509Extension.ConvertValueToObject((X509Extension) obj)); - } - - throw new ArgumentException("Invalid SubjectKeyIdentifier: " + Platform.GetTypeName(obj)); + return (SubjectKeyIdentifier)obj; + if (obj is SubjectPublicKeyInfo) + return new SubjectKeyIdentifier((SubjectPublicKeyInfo)obj); + if (obj is X509Extension) + return GetInstance(X509Extension.ConvertValueToObject((X509Extension)obj)); + if (obj == null) + return null; + return new SubjectKeyIdentifier(Asn1OctetString.GetInstance(obj)); } - public SubjectKeyIdentifier( + public static SubjectKeyIdentifier FromExtensions(X509Extensions extensions) + { + return GetInstance(X509Extensions.GetExtensionParsedValue(extensions, X509Extensions.SubjectKeyIdentifier)); + } + + private readonly byte[] keyIdentifier; + + public SubjectKeyIdentifier( byte[] keyID) { if (keyID == null) throw new ArgumentNullException("keyID"); - this.keyIdentifier = keyID; + this.keyIdentifier = Arrays.Clone(keyID); } public SubjectKeyIdentifier( Asn1OctetString keyID) + : this(keyID.GetOctets()) { - this.keyIdentifier = keyID.GetOctets(); } /** @@ -79,12 +69,12 @@ namespace Org.BouncyCastle.Asn1.X509 public byte[] GetKeyIdentifier() { - return keyIdentifier; + return Arrays.Clone(keyIdentifier); } - public override Asn1Object ToAsn1Object() + public override Asn1Object ToAsn1Object() { - return new DerOctetString(keyIdentifier); + return new DerOctetString(GetKeyIdentifier()); } /** |