internal static void Decode(AsnReader reader, out AlgorithmIdentifierAsn decoded)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            Decode(reader, Asn1Tag.Sequence, out decoded);
        }
示例#2
0
        internal static void Decode(AsnReader reader, out AlgorithmIdentifierAsn decoded)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            ReadOnlyMemory <byte> value = reader.GetEncodedValue();

            decoded = AsnSerializer.Deserialize <AlgorithmIdentifierAsn>(value, reader.RuleSet);
        }
示例#3
0
        internal RSASignaturePadding GetSignaturePadding(
            int?digestValueLength = null)
        {
            if (TrailerField != 1)
            {
                throw new CryptographicException(SR.Cryptography_Pkcs_InvalidSignatureParameters);
            }

            if (MaskGenAlgorithm.Algorithm != Oids.Mgf1)
            {
                throw new CryptographicException(
                          SR.Cryptography_Pkcs_PssParametersMgfNotSupported,
                          MaskGenAlgorithm.Algorithm);
            }

            if (MaskGenAlgorithm.Parameters == null)
            {
                throw new CryptographicException(SR.Cryptography_Pkcs_InvalidSignatureParameters);
            }

            AlgorithmIdentifierAsn mgfParams = AlgorithmIdentifierAsn.Decode(
                MaskGenAlgorithm.Parameters.Value,
                AsnEncodingRules.DER);

            if (mgfParams.Algorithm != HashAlgorithm.Algorithm)
            {
                throw new CryptographicException(
                          SR.Format(
                              SR.Cryptography_Pkcs_PssParametersMgfHashMismatch,
                              mgfParams.Algorithm,
                              HashAlgorithm.Algorithm));
            }

            int saltSize = digestValueLength.GetValueOrDefault();

            if (!digestValueLength.HasValue)
            {
                saltSize = Helpers.HashOidToByteLength(HashAlgorithm.Algorithm);
            }

            if (SaltLength != saltSize)
            {
                throw new CryptographicException(
                          SR.Format(
                              SR.Cryptography_Pkcs_PssParametersSaltMismatch,
                              SaltLength,
                              HashAlgorithm.Algorithm));
            }

            // When RSASignaturePadding supports custom salt sizes this return will look different.
            return(RSASignaturePadding.Pss);
        }
        internal static void Decode(AsnReader reader, Asn1Tag expectedTag, out AlgorithmIdentifierAsn decoded)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            decoded = default;
            AsnReader sequenceReader = reader.ReadSequence(expectedTag);

            decoded.Algorithm = sequenceReader.ReadObjectIdentifier();

            if (sequenceReader.HasData)
            {
                decoded.Parameters = sequenceReader.ReadEncodedValue();
            }


            sequenceReader.ThrowIfNotEmpty();
        }
示例#5
0
        internal bool Equals(ref AlgorithmIdentifierAsn other)
        {
            if (Algorithm.Value != other.Algorithm.Value)
            {
                return(false);
            }

            bool isNull      = RepresentsNull(Parameters);
            bool isOtherNull = RepresentsNull(other.Parameters);

            if (isNull != isOtherNull)
            {
                return(false);
            }

            if (isNull)
            {
                return(true);
            }

            return(Parameters.Value.Span.SequenceEqual(other.Parameters.Value.Span));
        }
        internal static void Decode(ref AsnValueReader reader, Asn1Tag expectedTag, ReadOnlyMemory <byte> rebind, out AlgorithmIdentifierAsn decoded)
        {
            decoded = default;
            AsnValueReader      sequenceReader = reader.ReadSequence(expectedTag);
            ReadOnlySpan <byte> rebindSpan     = rebind.Span;
            int offset;
            ReadOnlySpan <byte> tmpSpan;

            decoded.Algorithm = sequenceReader.ReadObjectIdentifier();

            if (sequenceReader.HasData)
            {
                tmpSpan            = sequenceReader.ReadEncodedValue();
                decoded.Parameters = rebindSpan.Overlaps(tmpSpan, out offset) ? rebind.Slice(offset, tmpSpan.Length) : tmpSpan.ToArray();
            }


            sequenceReader.ThrowIfNotEmpty();
        }
 internal static void Decode(ref AsnValueReader reader, ReadOnlyMemory <byte> rebind, out AlgorithmIdentifierAsn decoded)
 {
     Decode(ref reader, Asn1Tag.Sequence, rebind, out decoded);
 }
示例#8
0
 internal static void Decode(ref AsnValueReader reader, Asn1Tag expectedTag, ReadOnlyMemory <byte> rebind, out AlgorithmIdentifierAsn decoded)
 {
     try
     {
         DecodeCore(ref reader, expectedTag, rebind, out decoded);
     }
     catch (AsnContentException e)
     {
         throw new CryptographicException(SR.Cryptography_Der_Invalid_Encoding, e);
     }
 }