This repository has been archived by the owner on Jan 4, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
252a3f2
commit e34644d
Showing
148 changed files
with
20,614 additions
and
0 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,47 @@ | ||
using System; | ||
|
||
namespace Rubeus.Asn1 { | ||
public static class Asn1Extensions { | ||
|
||
public static byte[] DepadLeft(this byte[] data) { | ||
|
||
int leadingZeros = 0; | ||
for (var i = 0; i < data.Length; i++) { | ||
if (data[i] == 0) { | ||
leadingZeros++; | ||
} else { | ||
break; | ||
} | ||
} | ||
|
||
byte[] result = new byte[data.Length - leadingZeros]; | ||
Array.Copy(data, leadingZeros, result, 0, data.Length - leadingZeros); | ||
return result; | ||
} | ||
|
||
public static byte[] PadLeft(this byte[] data, int totalSize) { | ||
|
||
if(data.Length == totalSize) { | ||
return data; | ||
} | ||
|
||
if(totalSize < data.Length) { | ||
throw new ArgumentException("data bigger than totalSize, cannot pad with 0's"); | ||
} | ||
|
||
byte[] result = new byte[totalSize]; | ||
data.CopyTo(result, totalSize - data.Length); | ||
return result; | ||
} | ||
|
||
public static byte[] PadRight(this byte[] data, int length) { | ||
if (data.Length == length) { | ||
return data; | ||
} | ||
|
||
var copy = new byte[length]; | ||
data.CopyTo(copy, length - data.Length); | ||
return copy; | ||
} | ||
} | ||
} |
Oops, something went wrong.