예제 #1
0
        public void FromBytesThrowsBufferTooSmall(ContentTestCase @case)
        {
            byte[]          content     = GetDummyContent(@case);
            CoseHeaderValue headerValue = CoseHeaderValue.FromBytes(content.AsSpan());
            Memory <byte>   buffer      = new byte[content.Length - 1];

            Assert.Throws <ArgumentException>("destination", () => headerValue.GetValueAsBytes(buffer.Span));
        }
예제 #2
0
        public void FromBytesSucceeds(ContentTestCase @case)
        {
            byte[] content = GetDummyContent(@case);
            var    writer  = new CborWriter();

            writer.WriteByteString(content);
            byte[] encodedBytes = writer.Encode();

            CoseHeaderValue headerValue = CoseHeaderValue.FromBytes(content);

            AssertExtensions.SequenceEqual(encodedBytes, headerValue.EncodedValue.Span);
            AssertExtensions.SequenceEqual(content, headerValue.GetValueAsBytes());

            headerValue = CoseHeaderValue.FromBytes(content.AsSpan());
            AssertExtensions.SequenceEqual(encodedBytes, headerValue.EncodedValue.Span);

            Span <byte> buffer = new byte[content.Length];
            int         length = headerValue.GetValueAsBytes(buffer);

            AssertExtensions.SequenceEqual(content, buffer);
            Assert.Equal(content.Length, length);
        }