Skip to content

Commit 73974ad

Browse files
authored
feat: Migrate Base64 functions to Rust library (#23)
* feat: Add ConvertFrom-ByteArrayToString function (#15) Adds new function to convert byte arrays to strings with encoding support. Supports ASCII, BigEndianUnicode, Default, Unicode, UTF32, and UTF8 encodings. This is the inverse operation of ConvertFrom-StringToByteArray. - Add bytes_to_string Rust FFI function with 17 tests - Add ConvertFrom-ByteArrayToString PowerShell function with 43 Pester tests - Add DllImport binding in RustInterop.ps1 - Add function documentation and update CHANGELOG - Update ConvertFrom-StringToByteArray docs to reference inverse function * chore: bump version to 2.0.4-alpha * style: apply cargo fmt formatting to encoding.rs * feat: migrate ConvertFrom-Base64ToByteArray to Rust library - Replace .NET System.Convert.FromBase64String with Rust base64_to_bytes - Update ConvertFrom-Base64ToMemoryStream test for Rust error messages * feat: migrate ConvertFrom-Base64 to Rust library - Replace .NET System.Convert and System.Text.Encoding with Rust base64_to_string and base64_to_bytes - Update tests for Rust error messages
1 parent 59ec3a0 commit 73974ad

21 files changed

Lines changed: 1074 additions & 100 deletions

docs/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
### New Features
1515

16+
* **Added `ConvertFrom-ByteArrayToString`** - Converts byte arrays to strings with encoding support (Issue #15)
17+
* Supports ASCII, BigEndianUnicode, Default, Unicode, UTF32, and UTF8 encodings
18+
* Inverse operation of `ConvertFrom-StringToByteArray`
1619
* **Added `-Encoding` parameter** to `ConvertFrom-MemoryStreamToString` (Issue #21)
1720
* **Added `-Encoding` parameter** to `ConvertFrom-MemoryStreamToSecureString` (Issue #21)
1821
* **Added pipeline support** to `ConvertFrom-Base64ToByteArray` (Issue #16)

docs/functions/ConvertFrom-Base64ToByteArray.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
external help file: Convert-help.xml
33
Module Name: Convert
4-
online version: https://msdn.microsoft.com/en-us/library/system.convert.frombase64string%28v=vs.110%29.aspx
4+
online version: https://austoonz.github.io/Convert/functions/ConvertFrom-Base64ToByteArray/
55
schema: 2.0.0
66
---
77

@@ -13,7 +13,7 @@ Converts a Base 64 Encoded String to a Byte Array
1313
## SYNTAX
1414

1515
```
16-
ConvertFrom-Base64ToByteArray [-String] <String> [-ProgressAction <ActionPreference>] [<CommonParameters>]
16+
ConvertFrom-Base64ToByteArray [-String] <String[]> [-ProgressAction <ActionPreference>] [<CommonParameters>]
1717
```
1818

1919
## DESCRIPTION
@@ -24,28 +24,32 @@ Converts a Base 64 Encoded String to a Byte Array
2424
### EXAMPLE 1
2525
```
2626
ConvertFrom-Base64ToByteArray -String 'dGVzdA=='
27-
116
28-
101
29-
115
30-
116
3127
```
3228

33-
Converts the base64 string to its byte array representation.
29+
### EXAMPLE 2
30+
```
31+
'SGVsbG8=' | ConvertFrom-Base64ToByteArray
32+
```
33+
34+
### EXAMPLE 3
35+
```
36+
'SGVsbG8=', 'V29ybGQ=' | ConvertFrom-Base64ToByteArray
37+
```
3438

3539
## PARAMETERS
3640

3741
### -String
3842
The Base 64 Encoded String to be converted
3943

4044
```yaml
41-
Type: String
45+
Type: String[]
4246
Parameter Sets: (All)
4347
Aliases: Base64String
4448

4549
Required: True
4650
Position: 1
4751
Default value: None
48-
Accept pipeline input: False
52+
Accept pipeline input: True (ByPropertyName, ByValue)
4953
Accept wildcard characters: False
5054
```
5155
@@ -71,9 +75,10 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
7175
7276
## OUTPUTS
7377
78+
### [Byte[]]
7479
## NOTES
7580
7681
## RELATED LINKS
7782
78-
[https://msdn.microsoft.com/en-us/library/system.convert.frombase64string%28v=vs.110%29.aspx](https://msdn.microsoft.com/en-us/library/system.convert.frombase64string%28v=vs.110%29.aspx)
83+
[https://austoonz.github.io/Convert/functions/ConvertFrom-Base64ToByteArray/](https://austoonz.github.io/Convert/functions/ConvertFrom-Base64ToByteArray/)
7984

docs/functions/ConvertFrom-ByteArrayToMemoryStream.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
external help file: Convert-help.xml
33
Module Name: Convert
4-
online version: https://msdn.microsoft.com/en-us/library/system.io.memorystream(v=vs.110).aspx
4+
online version: https://austoonz.github.io/Convert/functions/ConvertFrom-ByteArrayToMemoryStream/
55
schema: 2.0.0
66
---
77

@@ -27,7 +27,11 @@ Converts a Byte Array to a MemoryStream
2727
ConvertFrom-ByteArrayToMemoryStream -ByteArray ([Byte[]] (,0xFF * 100))
2828
```
2929

30-
This command uses the ConvertFrom-ByteArrayToMemoryStream cmdlet to convert a Byte Array into a Memory Stream.
30+
### EXAMPLE 2
31+
```
32+
$bytes = [Byte[]]@(72, 101, 108, 108, 111)
33+
,$bytes | ConvertFrom-ByteArrayToMemoryStream
34+
```
3135

3236
## PARAMETERS
3337

@@ -42,7 +46,7 @@ Aliases: Bytes
4246
Required: True
4347
Position: 1
4448
Default value: None
45-
Accept pipeline input: False
49+
Accept pipeline input: True (ByPropertyName, ByValue)
4650
Accept wildcard characters: False
4751
```
4852
@@ -68,11 +72,10 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
6872
6973
## OUTPUTS
7074
75+
### [System.IO.MemoryStream[]]
7176
## NOTES
72-
Additional information:
73-
https://msdn.microsoft.com/en-us/library/63z365ty(v=vs.110).aspx
7477
7578
## RELATED LINKS
7679
77-
[https://msdn.microsoft.com/en-us/library/system.io.memorystream(v=vs.110).aspx](https://msdn.microsoft.com/en-us/library/system.io.memorystream(v=vs.110).aspx)
80+
[https://austoonz.github.io/Convert/functions/ConvertFrom-ByteArrayToMemoryStream/](https://austoonz.github.io/Convert/functions/ConvertFrom-ByteArrayToMemoryStream/)
7881
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
external help file: Convert-help.xml
3+
Module Name: Convert
4+
online version: https://austoonz.github.io/Convert/functions/ConvertFrom-ByteArrayToString/
5+
schema: 2.0.0
6+
---
7+
8+
# ConvertFrom-ByteArrayToString
9+
10+
## SYNOPSIS
11+
Converts a byte array to a string using the specified encoding.
12+
13+
## SYNTAX
14+
15+
```
16+
ConvertFrom-ByteArrayToString [-ByteArray] <Byte[]> [[-Encoding] <String>] [-ProgressAction <ActionPreference>]
17+
[<CommonParameters>]
18+
```
19+
20+
## DESCRIPTION
21+
Converts a byte array to a string using the specified encoding.
22+
This is the inverse operation of ConvertFrom-StringToByteArray.
23+
24+
## EXAMPLES
25+
26+
### EXAMPLE 1
27+
```
28+
$bytes = [byte[]]@(72, 101, 108, 108, 111)
29+
ConvertFrom-ByteArrayToString -ByteArray $bytes
30+
```
31+
32+
Hello
33+
34+
### EXAMPLE 2
35+
```
36+
$bytes = ConvertFrom-StringToByteArray -String 'Hello, World!'
37+
ConvertFrom-ByteArrayToString -ByteArray $bytes
38+
```
39+
40+
Hello, World!
41+
42+
### EXAMPLE 3
43+
```
44+
$bytes1, $bytes2 | ConvertFrom-ByteArrayToString -Encoding 'UTF8'
45+
```
46+
47+
Converts multiple byte arrays from the pipeline to strings.
48+
49+
## PARAMETERS
50+
51+
### -ByteArray
52+
The array of bytes to convert.
53+
54+
```yaml
55+
Type: Byte[]
56+
Parameter Sets: (All)
57+
Aliases:
58+
59+
Required: True
60+
Position: 1
61+
Default value: None
62+
Accept pipeline input: True (ByPropertyName, ByValue)
63+
Accept wildcard characters: False
64+
```
65+
66+
### -Encoding
67+
The encoding to use for conversion.
68+
Defaults to UTF8.
69+
Valid options are ASCII, BigEndianUnicode, Default, Unicode, UTF32, and UTF8.
70+
71+
```yaml
72+
Type: String
73+
Parameter Sets: (All)
74+
Aliases:
75+
76+
Required: False
77+
Position: 2
78+
Default value: UTF8
79+
Accept pipeline input: False
80+
Accept wildcard characters: False
81+
```
82+
83+
### -ProgressAction
84+
{{ Fill ProgressAction Description }}
85+
86+
```yaml
87+
Type: ActionPreference
88+
Parameter Sets: (All)
89+
Aliases: proga
90+
91+
Required: False
92+
Position: Named
93+
Default value: None
94+
Accept pipeline input: False
95+
Accept wildcard characters: False
96+
```
97+
98+
### CommonParameters
99+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
100+
101+
## INPUTS
102+
103+
## OUTPUTS
104+
105+
### [String]
106+
## NOTES
107+
108+
## RELATED LINKS
109+
110+
[https://austoonz.github.io/Convert/functions/ConvertFrom-ByteArrayToString/](https://austoonz.github.io/Convert/functions/ConvertFrom-ByteArrayToString/)
111+

docs/functions/ConvertFrom-MemoryStreamToSecureString.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ Converts a Memory Stream to a Secure String
1414

1515
### MemoryStream (Default)
1616
```
17-
ConvertFrom-MemoryStreamToSecureString -MemoryStream <MemoryStream[]> [-Encoding <String>] [-ProgressAction <ActionPreference>]
18-
[<CommonParameters>]
17+
ConvertFrom-MemoryStreamToSecureString -MemoryStream <MemoryStream[]> [-Encoding <String>]
18+
[-ProgressAction <ActionPreference>] [<CommonParameters>]
1919
```
2020

2121
### Stream
2222
```
23-
ConvertFrom-MemoryStreamToSecureString -Stream <Stream[]> [-Encoding <String>] [-ProgressAction <ActionPreference>]
24-
[<CommonParameters>]
23+
ConvertFrom-MemoryStreamToSecureString -Stream <Stream[]> [-Encoding <String>]
24+
[-ProgressAction <ActionPreference>] [<CommonParameters>]
2525
```
2626

2727
## DESCRIPTION

docs/functions/ConvertFrom-MemoryStreamToString.md

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ Converts MemoryStream to a string.
1212

1313
## SYNTAX
1414

15-
### MemoryStream
16-
```
17-
ConvertFrom-MemoryStreamToString -MemoryStream <MemoryStream[]> [-Encoding <String>] [-ProgressAction <ActionPreference>]
18-
[<CommonParameters>]
19-
```
20-
21-
### Stream
2215
```
2316
ConvertFrom-MemoryStreamToString -Stream <Stream[]> [-Encoding <String>] [-ProgressAction <ActionPreference>]
2417
[<CommonParameters>]
@@ -97,33 +90,19 @@ Another string
9790

9891
## PARAMETERS
9992

100-
### -MemoryStream
101-
A System.IO.MemoryStream object for conversion.
102-
103-
```yaml
104-
Type: MemoryStream[]
105-
Parameter Sets: MemoryStream
106-
Aliases:
107-
108-
Required: True
109-
Position: Named
110-
Default value: None
111-
Accept pipeline input: True (ByPropertyName, ByValue)
112-
Accept wildcard characters: False
113-
```
114-
11593
### -Stream
11694
A System.IO.Stream object for conversion.
95+
Accepts any stream type including MemoryStream, FileStream, etc.
11796

11897
```yaml
11998
Type: Stream[]
120-
Parameter Sets: Stream
121-
Aliases:
99+
Parameter Sets: (All)
100+
Aliases: MemoryStream
122101

123102
Required: True
124103
Position: Named
125104
Default value: None
126-
Accept pipeline input: True (ByPropertyName)
105+
Accept pipeline input: True (ByPropertyName, ByValue)
127106
Accept wildcard characters: False
128107
```
129108

docs/functions/ConvertFrom-StringToByteArray.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ ConvertFrom-StringToByteArray [-String] <String[]> [[-Encoding] <String>] [-Prog
1919

2020
## DESCRIPTION
2121
Converts a string to a byte array object.
22+
This is the inverse operation of ConvertFrom-ByteArrayToString.
2223

2324
## EXAMPLES
2425

docs/functions/ConvertTo-String.md

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ ConvertTo-String -Base64EncodedString <String[]> [-Encoding <String>] [-Decompre
1818
[-ProgressAction <ActionPreference>] [<CommonParameters>]
1919
```
2020

21-
### MemoryStream
22-
```
23-
ConvertTo-String -MemoryStream <MemoryStream[]> [-ProgressAction <ActionPreference>] [<CommonParameters>]
24-
```
25-
2621
### Stream
2722
```
2823
ConvertTo-String -Stream <Stream[]> [-ProgressAction <ActionPreference>] [<CommonParameters>]
@@ -120,33 +115,19 @@ Accept pipeline input: True (ByPropertyName, ByValue)
120115
Accept wildcard characters: False
121116
```
122117
123-
### -MemoryStream
124-
A MemoryStream object for conversion.
125-
126-
```yaml
127-
Type: MemoryStream[]
128-
Parameter Sets: MemoryStream
129-
Aliases:
130-
131-
Required: True
132-
Position: Named
133-
Default value: None
134-
Accept pipeline input: True (ByPropertyName, ByValue)
135-
Accept wildcard characters: False
136-
```
137-
138118
### -Stream
139119
A System.IO.Stream object for conversion.
120+
Accepts any stream type including MemoryStream, FileStream, etc.
140121
141122
```yaml
142123
Type: Stream[]
143124
Parameter Sets: Stream
144-
Aliases:
125+
Aliases: MemoryStream
145126

146127
Required: True
147128
Position: Named
148129
Default value: None
149-
Accept pipeline input: True (ByPropertyName)
130+
Accept pipeline input: True (ByPropertyName, ByValue)
150131
Accept wildcard characters: False
151132
```
152133

0 commit comments

Comments
 (0)