public void SignWithValidContent(ContentTestCase @case) { byte[] content = GetDummyContent(@case); ReadOnlySpan <byte> encodedMsg = Sign(content, DefaultKey, DefaultHash); AssertSign1Message(encodedMsg, content, DefaultKey, DefaultAlgorithm); }
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)); }
public void SignWithValidContent(ContentTestCase @case) { byte[] content = GetDummyContent(@case); AssertSign1Message(CoseSign1Message.Sign(content, DefaultKey, DefaultHash), content, DefaultKey); AssertSign1Message(CoseSign1Message.Sign(content, RSAKey, DefaultHash), content, RSAKey, GetExpectedProtectedHeaders((int)RSAAlgorithm.PS256)); AssertSign1Message(CoseSign1Message.Sign(content, GetHeaderMapWithAlgorithm(), GetEmptyHeaderMap(), DefaultKey, DefaultHash), content, DefaultKey); }
public void GetValueAsBytesSucceeds(ContentTestCase @case) { byte[] content = GetDummyContent(@case); var writer = new CborWriter(); writer.WriteByteString(content); CoseHeaderValue headerValue = CoseHeaderValue.FromEncodedValue(writer.Encode()); AssertExtensions.SequenceEqual(content, headerValue.GetValueAsBytes()); Span <byte> buffer = new byte[content.Length]; int length = headerValue.GetValueAsBytes(buffer); Assert.Equal(content.Length, length); AssertExtensions.SequenceEqual(content, buffer); }
public void GetValueAsBytesBeingIndefiniteLengthSucceeds(ContentTestCase @case) { Verify(0); Verify(1); Verify(10); void Verify(int repetitions) { byte[] content = GetDummyContent(@case); var writer = new CborWriter(); writer.WriteStartIndefiniteLengthByteString(); for (int i = 0; i < repetitions; i++) { writer.WriteByteString(content); } writer.WriteEndIndefiniteLengthByteString(); int expectedLength = content.Length * repetitions; CoseHeaderValue headerValue = CoseHeaderValue.FromEncodedValue(writer.Encode()); ReadOnlySpan <byte> result = headerValue.GetValueAsBytes(); Assert.Equal(expectedLength, result.Length); for (int i = 0; i < expectedLength; i += content.Length) { AssertExtensions.SequenceEqual(content, result.Slice(i, content.Length)); } Span <byte> buffer = new byte[expectedLength]; int length = headerValue.GetValueAsBytes(buffer); Assert.Equal(expectedLength, length); for (int i = 0; i < expectedLength; i += content.Length) { AssertExtensions.SequenceEqual(content, buffer.Slice(i, content.Length)); } } }