Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8cc21eb
Find / TryFind PEM
vcsjones Feb 12, 2020
508b09a
Implement GetEncodedSize.
vcsjones Feb 13, 2020
0b628d0
Added writing and complete doc-comments.
vcsjones Feb 13, 2020
b9c418f
Avoid an allocation for sensible label sizes.
vcsjones Feb 14, 2020
fb4e77c
Stackalloc outside loop once.
vcsjones Feb 14, 2020
7965127
Fix Windows line handling.
vcsjones Feb 14, 2020
558a937
Code review feedback.
vcsjones Feb 19, 2020
8d8c34b
Document value of PemFields.
vcsjones Feb 19, 2020
69dfb80
Document exception for Write and TryWrite.
vcsjones Feb 19, 2020
13beb43
whitespace => white space
vcsjones Feb 19, 2020
4ee4b1c
Rewrite in terms without lines.
vcsjones Feb 19, 2020
2362abf
Minor refactoring
vcsjones Feb 19, 2020
2745dfa
Add test for mismatched labels
vcsjones Feb 19, 2020
0c71711
Fix label validation.
vcsjones Feb 20, 2020
8107961
Validate label when writing.
vcsjones Feb 20, 2020
9a84a4d
Use clearer increment.
vcsjones Feb 20, 2020
3985611
Documentation feedback.
vcsjones Feb 21, 2020
5c9ebd3
Formatting cleanup.
vcsjones Feb 21, 2020
8ceff01
Remove line handling tests.
vcsjones Feb 21, 2020
43ed5b5
Some test refactoring.
vcsjones Feb 25, 2020
a991f1e
WIP
vcsjones Mar 10, 2020
7dbbfde
Merge remote-tracking branch 'ms/master' into one-shot-pem
vcsjones Mar 10, 2020
422a8ed
Fix tests and base64 location
vcsjones Mar 10, 2020
3a222ee
Use an offset helper to reduce IndexOf gymnastics.
vcsjones Mar 10, 2020
919ba8a
Rename
vcsjones Mar 10, 2020
348f997
Re-organize tests.
vcsjones Mar 17, 2020
11ad108
Formatting
vcsjones Mar 17, 2020
3150dd5
Fixup decoding size calculation to not overflow an int
vcsjones Mar 17, 2020
3f6738e
Additional code review feedback.
vcsjones Mar 17, 2020
bf18476
Remove duplicate tests.
vcsjones Mar 17, 2020
16cf85a
Add additional tests for base64 padding.
vcsjones Mar 17, 2020
0ede347
Additional tests.
vcsjones Mar 18, 2020
b78ef7e
Improve assert extensions.
vcsjones Mar 18, 2020
430d2c6
Remove wrapping that is not required
vcsjones Mar 18, 2020
159df24
Add comment explaining label composition.
vcsjones Mar 18, 2020
7b9c08f
Brace for impact.
vcsjones Mar 18, 2020
27e120c
Remove open-ended ranges and use Slice.
vcsjones Mar 18, 2020
f3538cc
Correct IsValidLabel.
vcsjones Mar 18, 2020
dff24c1
Test additions.
vcsjones Mar 19, 2020
19f45b2
Fix test names
vcsjones Mar 19, 2020
6735d32
More specific definition of white space.
vcsjones Mar 19, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public static void AtLeastOneEquals<T>(T expected1, T expected2, T value)
public delegate void AssertThrowsAction<T>(Span<T> span);

// Cannot use standard Assert.Throws() when testing Span - Span and closures don't get along.
public static void AssertThrows<E, T>(ReadOnlySpan<T> span, AssertThrowsActionReadOnly<T> action) where E : Exception
public static E AssertThrows<E, T>(ReadOnlySpan<T> span, AssertThrowsActionReadOnly<T> action) where E : Exception
{
Exception exception;

Expand All @@ -404,18 +404,18 @@ public static void AssertThrows<E, T>(ReadOnlySpan<T> span, AssertThrowsActionRe
exception = ex;
}

if (exception == null)
switch(exception)
{
throw new ThrowsException(typeof(E));
}

if (exception.GetType() != typeof(E))
{
throw new ThrowsException(typeof(E), exception);
case null:
throw new ThrowsException(typeof(E));
case E ex when (ex.GetType() == typeof(E)):
return ex;
default:
throw new ThrowsException(typeof(E), exception);
}
}

public static void AssertThrows<E, T>(Span<T> span, AssertThrowsAction<T> action) where E : Exception
public static E AssertThrows<E, T>(Span<T> span, AssertThrowsAction<T> action) where E : Exception
{
Exception exception;

Expand All @@ -429,15 +429,31 @@ public static void AssertThrows<E, T>(Span<T> span, AssertThrowsAction<T> action
exception = ex;
}

if (exception == null)
switch(exception)
{
throw new ThrowsException(typeof(E));
case null:
throw new ThrowsException(typeof(E));
case E ex when (ex.GetType() == typeof(E)):
return ex;
default:
throw new ThrowsException(typeof(E), exception);
}
}

if (exception.GetType() != typeof(E))
{
throw new ThrowsException(typeof(E), exception);
}
public static E Throws<E, T>(string expectedParamName, ReadOnlySpan<T> span, AssertThrowsActionReadOnly<T> action)
where E : ArgumentException
{
E exception = AssertThrows<E, T>(span, action);
Assert.Equal(expectedParamName, exception.ParamName);
return exception;
}

public static E Throws<E, T>(string expectedParamName, Span<T> span, AssertThrowsAction<T> action)
where E : ArgumentException
{
E exception = AssertThrows<E, T>(span, action);
Assert.Equal(expectedParamName, exception.ParamName);
return exception;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@ public enum OidGroup
Template = 9,
KeyDerivationFunction = 10,
}
public static partial class PemEncoding
{
public static System.Security.Cryptography.PemFields Find(System.ReadOnlySpan<char> pemData) { throw null; }
public static int GetEncodedSize(int labelLength, int dataLength) { throw null; }
public static bool TryFind(System.ReadOnlySpan<char> pemData, out System.Security.Cryptography.PemFields fields) { throw null; }
public static bool TryWrite(System.ReadOnlySpan<char> label, System.ReadOnlySpan<byte> data, System.Span<char> destination, out int charsWritten) { throw null; }
public static char[] Write(System.ReadOnlySpan<char> label, System.ReadOnlySpan<byte> data) { throw null; }
}
public readonly partial struct PemFields
{
private readonly object _dummy;
private readonly int _dummyPrimitive;
public System.Range Base64Data { get { throw null; } }
public int DecodedDataLength { get { throw null; } }
public System.Range Label { get { throw null; } }
public System.Range Location { get { throw null; } }
}
public partial class ToBase64Transform : System.IDisposable, System.Security.Cryptography.ICryptoTransform
{
public ToBase64Transform() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@
<data name="Argument_InvalidValue" xml:space="preserve">
<value>Value was invalid.</value>
</data>
<data name="Argument_PemEncoding_NoPemFound" xml:space="preserve">
<value>No PEM encoded data found.</value>
</data>
<data name="Argument_PemEncoding_InvalidLabel" xml:space="preserve">
<value>The specified label is not valid.</value>
</data>
<data name="Argument_PemEncoding_EncodedSizeTooLarge" xml:space="preserve">
<value>The encoded PEM size is too large to represent as a signed 32-bit integer.</value>
</data>
<data name="ArgumentOutOfRange_NeedPositiveNumber" xml:space="preserve">
<value>A positive number is required.</value>
</data>
<data name="ObjectDisposed_Generic" xml:space="preserve">
<value>Cannot access a disposed object.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<Compile Include="System\Security\Cryptography\OidCollection.cs" />
<Compile Include="System\Security\Cryptography\OidEnumerator.cs" />
<Compile Include="System\Security\Cryptography\OidGroup.cs" />
<Compile Include="System\Security\Cryptography\PemFields.cs" />
<Compile Include="System\Security\Cryptography\PemEncoding.cs" />
<Compile Include="$(CommonPath)Internal\Cryptography\Helpers.cs">
<Link>Internal\Cryptography\Helpers.cs</Link>
</Compile>
Expand Down Expand Up @@ -147,4 +149,4 @@
<Reference Include="System.Runtime.Numerics" />
<Reference Include="System.Threading" />
</ItemGroup>
</Project>
</Project>
Loading