-
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 branch 'refs/heads/main' into release
- Loading branch information
Showing
9 changed files
with
198 additions
and
8 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
22 changes: 22 additions & 0 deletions
22
OnixLabs.Security.Cryptography/DigitalSignatureAndPublicKey.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,22 @@ | ||
// Copyright 2020 ONIXLabs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace OnixLabs.Security.Cryptography; | ||
|
||
/// <summary> | ||
/// Represents a pair of a cryptography digital signature, and a named cryptographic public key. | ||
/// </summary> | ||
/// <param name="Signature">The underlying cryptographic digital signature.</param> | ||
/// <param name="Key">The underlying named cryptographic public key.</param> | ||
public readonly record struct DigitalSignatureAndPublicKey(DigitalSignature Signature, NamedPublicKey Key); |
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,40 @@ | ||
// Copyright 2020 ONIXLabs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using OnixLabs.Core.Text; | ||
|
||
namespace OnixLabs.Security.Cryptography; | ||
|
||
public readonly partial record struct NamedPrivateKey | ||
{ | ||
/// <summary> | ||
/// Gets the underlying <see cref="T:Byte[]"/> representation of the underlying <see cref="NamedPrivateKey"/> instance. | ||
/// </summary> | ||
/// <returns>Return the underlying <see cref="T:Byte[]"/> representation of the underlying <see cref="NamedPrivateKey"/> instance.</returns> | ||
public byte[] ToByteArray() => PrivateKey.ToByteArray(); | ||
|
||
/// <summary> | ||
/// Returns a <see cref="string"/> that represents the current object. | ||
/// </summary> | ||
/// <param name="provider">The format provider that will be used to determine the format of the string.</param> | ||
/// <returns>Returns a <see cref="string"/> that represents the current object.</returns> | ||
public string ToString(IFormatProvider provider) => $"{AlgorithmName}:{IBaseCodec.GetString(ToByteArray(), provider)}"; | ||
|
||
/// <summary> | ||
/// Returns a <see cref="string"/> that represents the current object. | ||
/// </summary> | ||
/// <returns>Returns a <see cref="string"/> that represents the current object.</returns> | ||
public override string ToString() => ToString(Base16FormatProvider.Invariant); | ||
} |
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,44 @@ | ||
// Copyright 2020 ONIXLabs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace OnixLabs.Security.Cryptography; | ||
|
||
/// <summary> | ||
/// Represents a named cryptographic private key. | ||
/// </summary> | ||
public readonly partial record struct NamedPrivateKey : ICryptoPrimitive<NamedPrivateKey> | ||
{ | ||
private const string KeyAlgorithmNameNullOrWhiteSpace = "Key algorithm name must not be null or whitespace."; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="NamedPrivateKey"/> struct. | ||
/// </summary> | ||
/// <param name="privateKey">The underlying private key value.</param> | ||
/// <param name="algorithmName">The name of the key algorithm that was used to produce the associated private key.</param> | ||
public NamedPrivateKey(PrivateKey privateKey, string algorithmName) | ||
{ | ||
PrivateKey = privateKey; | ||
AlgorithmName = RequireNotNullOrWhiteSpace(algorithmName, KeyAlgorithmNameNullOrWhiteSpace); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the underlying private key value. | ||
/// </summary> | ||
public PrivateKey PrivateKey { get; } | ||
|
||
/// <summary> | ||
/// Gets the name of the key algorithm that was used to produce the associated private key. | ||
/// </summary> | ||
public string AlgorithmName { get; } | ||
} |
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,40 @@ | ||
// Copyright 2020 ONIXLabs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using OnixLabs.Core.Text; | ||
|
||
namespace OnixLabs.Security.Cryptography; | ||
|
||
public readonly partial record struct NamedPublicKey | ||
{ | ||
/// <summary> | ||
/// Gets the underlying <see cref="T:Byte[]"/> representation of the underlying <see cref="NamedPublicKey"/> instance. | ||
/// </summary> | ||
/// <returns>Return the underlying <see cref="T:Byte[]"/> representation of the underlying <see cref="NamedPublicKey"/> instance.</returns> | ||
public byte[] ToByteArray() => PublicKey.ToByteArray(); | ||
|
||
/// <summary> | ||
/// Returns a <see cref="string"/> that represents the current object. | ||
/// </summary> | ||
/// <param name="provider">The format provider that will be used to determine the format of the string.</param> | ||
/// <returns>Returns a <see cref="string"/> that represents the current object.</returns> | ||
public string ToString(IFormatProvider provider) => $"{AlgorithmName}:{IBaseCodec.GetString(ToByteArray(), provider)}"; | ||
|
||
/// <summary> | ||
/// Returns a <see cref="string"/> that represents the current object. | ||
/// </summary> | ||
/// <returns>Returns a <see cref="string"/> that represents the current object.</returns> | ||
public override string ToString() => ToString(Base16FormatProvider.Invariant); | ||
} |
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,44 @@ | ||
// Copyright 2020 ONIXLabs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace OnixLabs.Security.Cryptography; | ||
|
||
/// <summary> | ||
/// Represents a named cryptographic public key. | ||
/// </summary> | ||
public readonly partial record struct NamedPublicKey : ICryptoPrimitive<NamedPublicKey> | ||
{ | ||
private const string KeyAlgorithmNameNullOrWhiteSpace = "Key algorithm name must not be null or whitespace."; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="NamedPublicKey"/> struct. | ||
/// </summary> | ||
/// <param name="publicKey">The underlying public key value.</param> | ||
/// <param name="algorithmName">The name of the key algorithm that was used to produce the associated public key.</param> | ||
public NamedPublicKey(PublicKey publicKey, string algorithmName) | ||
{ | ||
PublicKey = publicKey; | ||
AlgorithmName = RequireNotNullOrWhiteSpace(algorithmName, KeyAlgorithmNameNullOrWhiteSpace); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the underlying public key value. | ||
/// </summary> | ||
public PublicKey PublicKey { get; } | ||
|
||
/// <summary> | ||
/// Gets the name of the key algorithm that was used to produce the associated public key. | ||
/// </summary> | ||
public string AlgorithmName { get; } | ||
} |
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