File: Internal\Cryptography\Pal\AnyOS\ManagedPal.Asn.cs
Web Access
Project: src\src\libraries\System.Security.Cryptography.Pkcs\src\System.Security.Cryptography.Pkcs.csproj (System.Security.Cryptography.Pkcs)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
 
using System;
using System.Buffers;
using System.Formats.Asn1;
using System.Security.Cryptography;
using System.Security.Cryptography.Asn1.Pkcs7;
 
namespace Internal.Cryptography.Pal.AnyOS
{
    internal sealed partial class ManagedPkcsPal : PkcsPal
    {
        public override Oid GetEncodedMessageType(ReadOnlySpan<byte> encodedMessage)
        {
            ValueAsnReader reader = new ValueAsnReader(encodedMessage, AsnEncodingRules.BER);
            ValueContentInfoAsn.Decode(ref reader, out ValueContentInfoAsn contentInfo);
 
            switch (contentInfo.ContentType)
            {
                case Oids.Pkcs7Data:
                case Oids.Pkcs7Signed:
                case Oids.Pkcs7Enveloped:
                case Oids.Pkcs7SignedEnveloped:
                case Oids.Pkcs7Hashed:
                case Oids.Pkcs7Encrypted:
                    return new Oid(contentInfo.ContentType);
            }
 
            throw new CryptographicException(SR.Cryptography_Cms_InvalidMessageType);
        }
    }
}