-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PrivateKeyCredential: fix issue when loading some RSA keys.
- Loading branch information
Showing
2 changed files
with
30 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace Tmds.Ssh; | ||
|
||
static class BigIntegerExtensions | ||
{ | ||
public static byte[] ToBEByteArray(this BigInteger integer, bool isUnsigned, int minLength) | ||
Check failure on line 5 in src/Tmds.Ssh/BigIntegerExtensions.cs GitHub Actions / build
Check failure on line 5 in src/Tmds.Ssh/BigIntegerExtensions.cs GitHub Actions / build
Check failure on line 5 in src/Tmds.Ssh/BigIntegerExtensions.cs GitHub Actions / build
|
||
{ | ||
int bytesNeeded = integer.GetByteCount(isUnsigned); | ||
int length = Math.Max(bytesNeeded, minLength); | ||
byte[] array = new byte[length]; | ||
int prefixLength = length - bytesNeeded; | ||
bool success = integer.TryWriteBytes(array.AsSpan(prefixLength), out _, isUnsigned, isBigEndian: true); | ||
Debug.Assert(success); // Can't fail since the array is large enough. | ||
if (prefixLength != 0 && integer.Sign < 0) | ||
{ | ||
array.AsSpan(0, prefixLength).Fill(0xff); | ||
} | ||
return array; | ||
} | ||
} |
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