-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from dmariogatto/dev-net6
net6.0
- Loading branch information
Showing
42 changed files
with
12,222 additions
and
8,599 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/Cats.CertificateTransparency/Extensions/SpanExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.IO; | ||
|
||
namespace Cats.CertificateTransparency.Extensions | ||
{ | ||
internal static class SpanExtensions | ||
{ | ||
internal static long ReadLong(this Span<byte> span, int bytesToRead, ref int position) | ||
{ | ||
if (bytesToRead > Constants.BytesInLong) | ||
throw new ArgumentOutOfRangeException(nameof(bytesToRead), $"Cannot read long of length {bytesToRead} bytes"); | ||
|
||
var result = 0L; | ||
|
||
for (var i = 0; i < bytesToRead; i++) | ||
{ | ||
var readVal = span[position++]; | ||
result = (result << Constants.BitsInByte) | readVal; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
internal static Span<byte> ReadVariableLength(this Span<byte> span, int maxDataValue, ref int position) | ||
{ | ||
var bytesForDataLength = Constants.BytesToStoreValue(maxDataValue); | ||
var dataLength = ReadLong(span, bytesForDataLength, ref position); | ||
|
||
var data = span.Slice(position, (int)dataLength); | ||
position += data.Length; | ||
|
||
if (data.Length != dataLength) throw new IOException($"Incomplete data. Expected {dataLength} bytes, got {span.Length}"); | ||
|
||
return data; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.