From 765426a8dc1fe20295f91d55e7bbf539e6b831fc Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Thu, 20 Feb 2020 01:37:07 +0700 Subject: Misc. updates from bc-java --- crypto/src/asn1/nist/NISTObjectIdentifiers.cs | 4 ++++ crypto/src/asn1/pkcs/CertBag.cs | 16 ++++++++++++---- crypto/src/cms/CMSSignedData.cs | 10 ++++++++++ crypto/src/tsp/TimeStampToken.cs | 15 ++++++++++++--- 4 files changed, 38 insertions(+), 7 deletions(-) (limited to 'crypto/src') diff --git a/crypto/src/asn1/nist/NISTObjectIdentifiers.cs b/crypto/src/asn1/nist/NISTObjectIdentifiers.cs index 840718ccd..417fa8df9 100644 --- a/crypto/src/asn1/nist/NISTObjectIdentifiers.cs +++ b/crypto/src/asn1/nist/NISTObjectIdentifiers.cs @@ -35,6 +35,10 @@ namespace Org.BouncyCastle.Asn1.Nist public static readonly DerObjectIdentifier IdHMacWithSha3_256 = HashAlgs.Branch("14"); public static readonly DerObjectIdentifier IdHMacWithSha3_384 = HashAlgs.Branch("15"); public static readonly DerObjectIdentifier IdHMacWithSha3_512 = HashAlgs.Branch("16"); + public static readonly DerObjectIdentifier IdShake128Len = HashAlgs.Branch("17"); + public static readonly DerObjectIdentifier IdShake256Len = HashAlgs.Branch("18"); + public static readonly DerObjectIdentifier IdKmacWithShake128 = HashAlgs.Branch("19"); + public static readonly DerObjectIdentifier IdKmacWithShake256 = HashAlgs.Branch("20"); public static readonly DerObjectIdentifier Aes = new DerObjectIdentifier(NistAlgorithm + ".1"); diff --git a/crypto/src/asn1/pkcs/CertBag.cs b/crypto/src/asn1/pkcs/CertBag.cs index e561fb890..61165c087 100644 --- a/crypto/src/asn1/pkcs/CertBag.cs +++ b/crypto/src/asn1/pkcs/CertBag.cs @@ -5,17 +5,25 @@ namespace Org.BouncyCastle.Asn1.Pkcs public class CertBag : Asn1Encodable { -// private readonly Asn1Sequence seq; + public static CertBag GetInstance(object obj) + { + if (obj is CertBag) + return (CertBag)obj; + if (obj == null) + return null; + return new CertBag(Asn1Sequence.GetInstance(obj)); + } + private readonly DerObjectIdentifier certID; private readonly Asn1Object certValue; + [Obsolete("Use 'GetInstance' instead")] public CertBag( Asn1Sequence seq) { if (seq.Count != 2) throw new ArgumentException("Wrong number of elements in sequence", "seq"); -// this.seq = seq; this.certID = DerObjectIdentifier.GetInstance(seq[0]); this.certValue = Asn1TaggedObject.GetInstance(seq[1]).GetObject(); } @@ -28,12 +36,12 @@ namespace Org.BouncyCastle.Asn1.Pkcs this.certValue = certValue; } - public DerObjectIdentifier CertID + public virtual DerObjectIdentifier CertID { get { return certID; } } - public Asn1Object CertValue + public virtual Asn1Object CertValue { get { return certValue; } } diff --git a/crypto/src/cms/CMSSignedData.cs b/crypto/src/cms/CMSSignedData.cs index 979be6535..8634b2b3a 100644 --- a/crypto/src/cms/CMSSignedData.cs +++ b/crypto/src/cms/CMSSignedData.cs @@ -280,6 +280,16 @@ namespace Org.BouncyCastle.Cms return contentInfo.GetEncoded(); } + /** + * return the ASN.1 encoded representation of this object using the specified encoding. + * + * @param encoding the ASN.1 encoding format to use ("BER" or "DER"). + */ + public byte[] GetEncoded(string encoding) + { + return contentInfo.GetEncoded(encoding); + } + /** * Replace the signerinformation store associated with this * CmsSignedData object with the new one passed in. You would diff --git a/crypto/src/tsp/TimeStampToken.cs b/crypto/src/tsp/TimeStampToken.cs index 105208a7d..643813552 100644 --- a/crypto/src/tsp/TimeStampToken.cs +++ b/crypto/src/tsp/TimeStampToken.cs @@ -244,9 +244,18 @@ namespace Org.BouncyCastle.Tsp */ public byte[] GetEncoded() { - return tsToken.GetEncoded(); - } - + return tsToken.GetEncoded(Asn1Encodable.Der); + } + + /** + * return the ASN.1 encoded representation of this object using the specified encoding. + * + * @param encoding the ASN.1 encoding format to use ("BER" or "DER"). + */ + public byte[] GetEncoded(string encoding) + { + return tsToken.GetEncoded(encoding); + } // perhaps this should be done using an interface on the ASN.1 classes... private class CertID -- cgit 1.4.1