コード例 #1
0
        internal static bool TryReadTagAndLength(ReadOnlySequence <byte> buffer, out long length)
        {
            if (buffer.IsSingleSegment)
            {
                return(TryReadTagAndLength(buffer.First, out length));
            }

            length = 0;
            if (!AsnReader.TryPeekTag(buffer.First.Span, out _, out int tagBytes))
            {
                return(false);
            }
            buffer = buffer.Slice(tagBytes);
            if (!AsnReader.TryReadLength(buffer.First.Span, AsnEncodingRules.BER, out var asnLength, out var lengthBytes))
            {
                return(false);
            }
            if (!asnLength.HasValue)
            {
                return(false);
            }
            length  = asnLength.Value;
            length += lengthBytes;
            length += tagBytes;
            return(true);
        }
コード例 #2
0
 private static bool TryReadTagAndLength(ReadOnlyMemory <byte> buffer, out long length)
 {
     length = 0;
     if (!AsnReader.TryPeekTag(buffer.Span, out _, out int tagBytes))
     {
         return(false);
     }
     if (!AsnReader.TryReadLength(buffer.Span.Slice(tagBytes), AsnEncodingRules.BER, out var asnLength, out var lengthBytes))
     {
         return(false);
     }
     if (!asnLength.HasValue)
     {
         return(false);
     }
     length  = asnLength.Value;
     length += lengthBytes;
     length += tagBytes;
     return(true);
 }