- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 941
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This makes it easier to reason about Key instances in e.g. DigitalSignature implementations, because we know that the Key is initialised with its data and will not change. Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
1 parent
e998d87
commit 24838e6
Showing
15 changed files
with
295 additions
and
516 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
using Renci.SshNet.Common; | ||
using Renci.SshNet.Security.Chaos.NaCl; | ||
|
||
namespace Renci.SshNet.Security | ||
{ | ||
/// <summary> | ||
/// Facilitates (de)serializing encoded public key data in the format | ||
/// specified by RFC 4253 section 6.6. | ||
/// </summary> | ||
/// <remarks> | ||
/// See https://datatracker.ietf.org/doc/html/rfc4253#section-6.6. | ||
/// </remarks> | ||
public sealed class SshKeyData : SshData | ||
{ | ||
/// <summary> | ||
/// Gets the public key format identifier. | ||
/// </summary> | ||
public string Name { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets the public key constituents. | ||
/// </summary> | ||
public BigInteger[] Keys { get; private set; } | ||
|
||
/// <inheritdoc/> | ||
protected override int BufferCapacity | ||
{ | ||
get | ||
{ | ||
var capacity = base.BufferCapacity; | ||
capacity += 4; // Name length | ||
capacity += Encoding.UTF8.GetByteCount(Name); // Name | ||
|
||
foreach (var key in Keys) | ||
{ | ||
capacity += 4; // Key length | ||
capacity += key.BitLength / 8; // Key | ||
} | ||
|
||
return capacity; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="SshKeyData"/> class. | ||
/// </summary> | ||
/// <param name="data">The encoded public key data.</param> | ||
public SshKeyData(byte[] data) | ||
{ | ||
Load(data); | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="SshKeyData"/> class. | ||
/// </summary> | ||
/// <param name="name">The public key format identifer.</param> | ||
/// <param name="keys">The public key constituents.</param> | ||
public SshKeyData(string name, BigInteger[] keys) | ||
{ | ||
Name = name; | ||
Keys = keys; | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override void LoadData() | ||
{ | ||
Name = ReadString(); | ||
var keys = new List<BigInteger>(); | ||
|
||
while (!IsEndOfData) | ||
{ | ||
keys.Add(ReadBinary().ToBigInteger2()); | ||
} | ||
|
||
Keys = keys.ToArray(); | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override void SaveData() | ||
{ | ||
Write(Name); | ||
|
||
foreach (var key in Keys) | ||
{ | ||
var keyData = key.ToByteArray().Reverse(); | ||
if (Name == "ssh-ed25519") | ||
{ | ||
keyData = keyData.TrimLeadingZeros().Pad(Ed25519.PublicKeySizeInBytes); | ||
} | ||
|
||
WriteBinaryString(keyData); | ||
} | ||
} | ||
} | ||
} |
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
49 changes: 0 additions & 49 deletions
49
test/Renci.SshNet.Benchmarks/Security/Cryptography/Ciphers/RsaCipherBenchmarks.cs
This file was deleted.
Oops, something went wrong.
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