diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2021-11-16 22:37:52 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2021-11-16 22:37:52 +0700 |
commit | be15049124860ccb7335b92215e8b8dfa1821bf9 (patch) | |
tree | 7a86ed2110021307465a617076d601ca812c69ed /crypto/src/asn1/PrimitiveEncodingSuffixed.cs | |
parent | Make cast more specific (diff) | |
download | BouncyCastle.NET-ed25519-be15049124860ccb7335b92215e8b8dfa1821bf9.tar.xz |
ASN.1: Staged encoding
Diffstat (limited to 'crypto/src/asn1/PrimitiveEncodingSuffixed.cs')
-rw-r--r-- | crypto/src/asn1/PrimitiveEncodingSuffixed.cs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/crypto/src/asn1/PrimitiveEncodingSuffixed.cs b/crypto/src/asn1/PrimitiveEncodingSuffixed.cs new file mode 100644 index 000000000..ef0ef49ac --- /dev/null +++ b/crypto/src/asn1/PrimitiveEncodingSuffixed.cs @@ -0,0 +1,36 @@ +using System; + +namespace Org.BouncyCastle.Asn1 +{ + internal class PrimitiveEncodingSuffixed + : IAsn1Encoding + { + private readonly int m_tagClass; + private readonly int m_tagNo; + private readonly byte[] m_contentsOctets; + private readonly byte m_contentsSuffix; + + internal PrimitiveEncodingSuffixed(int tagClass, int tagNo, byte[] contentsOctets, byte contentsSuffix) + { + m_tagClass = tagClass; + m_tagNo = tagNo; + m_contentsOctets = contentsOctets; + m_contentsSuffix = contentsSuffix; + } + + void IAsn1Encoding.Encode(Asn1OutputStream asn1Out) + { + asn1Out.WriteIdentifier(m_tagClass, m_tagNo); + asn1Out.WriteDL(m_contentsOctets.Length); + asn1Out.Write(m_contentsOctets, 0, m_contentsOctets.Length - 1); + asn1Out.WriteByte(m_contentsSuffix); + } + + int IAsn1Encoding.GetLength() + { + return Asn1OutputStream.GetLengthOfIdentifier(m_tagNo) + + Asn1OutputStream.GetLengthOfDL(m_contentsOctets.Length) + + m_contentsOctets.Length; + } + } +} |