Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions examples/General.ps1

This file was deleted.

35 changes: 35 additions & 0 deletions src/functions/public/ConvertFrom-Base64.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
filter ConvertFrom-Base64 {
<#
.SYNOPSIS
Convert to string from base64

.DESCRIPTION
Converts a base64 encoded string to a string.

.EXAMPLE
ConvertFrom-Base64 -Base64String 'VGhpc0lzQU5pY2VTdHJpbmc='
ThisIsANiceString

Converts the base64 encoded string 'VGhpc0lzQU5pY2VTdHJpbmc=' to a string.

.EXAMPLE
'SGVsbG8gV29ybGQ=' | ConvertFrom-Base64String
Hello World

Converts the string from base64 to a regular string.
#>
[Alias('ConvertFrom-Base64String')]
[OutputType([string])]
[CmdletBinding()]
param(
# The base64 encoded string to convert.
[Parameter(
Mandatory,
ValueFromPipeline
)]
[ValidateScript({ Test-Base64 -Base64String $_ }, ErrorMessage = 'Invalid Base64 string')]
[string] $Base64String
)

return [System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($Base64String))
}
34 changes: 34 additions & 0 deletions src/functions/public/ConvertTo-Base64.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
filter ConvertTo-Base64 {
<#
.SYNOPSIS
Convert a string to base64

.DESCRIPTION
Converts a string to a base64 encoded string.

.EXAMPLE
ConvertTo-Base64 -String 'ThisIsANiceString'
VGhpc0lzQU5pY2VTdHJpbmc=

Converts the string 'ThisIsANiceString' to a base64 encoded string.

.EXAMPLE
'Hello World' | ConvertTo-Base64
SGVsbG8gV29ybGQ=

Converts the string 'Hello World' to base64.
#>
[Alias('ConvertTo-Base64String')]
[OutputType([string])]
[CmdletBinding()]
param(
# The string to convert to base64
[Parameter(
Mandatory,
ValueFromPipeline,
ValueFromPipelineByPropertyName
)]
[string] $String
)
return [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($String))
}
20 changes: 0 additions & 20 deletions src/functions/public/Get-PSModuleTest.ps1

This file was deleted.

37 changes: 37 additions & 0 deletions src/functions/public/Test-Base64.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
filter Test-Base64 {
<#
.SYNOPSIS
Test if a string is a valid base64 string.

.DESCRIPTION
Test if a string is a valid base64 string.

.EXAMPLE
Test-Base64 -Base64String 'U29tZSBkYXRh'
True

Returns $true as the string is a valid base64 string.

.EXAMPLE
'U29tZSBkYXRh' | Test-Base64
True

Returns $true as the string is a valid base64 string.
#>
[OutputType([bool])]
[CmdletBinding()]
param (
[Parameter(
Mandatory,
ValueFromPipeline
)]
[string] $Base64String
)

try {
$null = [Convert]::FromBase64String($Base64String)
return $true
} catch {
return $false
}
}
34 changes: 24 additions & 10 deletions tests/Module.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
Describe 'Module' {
It 'Function: Get-PSModuleTest' {
Get-PSModuleTest -Name 'World' | Should -Be 'Hello, World!'
Describe 'Base64' {
Context 'Function: Test-Base64' {
It "Test-Base64 -Base64String 'VGhpc0lzQU5pY2VTdHJpbmc=' -> true" {
Test-Base64 -Base64String 'VGhpc0lzQU5pY2VTdHJpbmc=' | Should -Be $true
}
It "'SGVsbG8gV29ybGQ=' | Test-Base64 -> true" {
'SGVsbG8gV29ybGQ=' | Test-Base64 | Should -Be $true
}
}
It 'Function: New-PSModuleTest' {
New-PSModuleTest -Name 'World' | Should -Be 'Hello, World!'
Context 'Function: ConvertTo-Base64' {
It "ConvertTo-Base64 -String 'ThisIsANiceString' -> VGhpc0lzQU5pY2VTdHJpbmc=" {
ConvertTo-Base64 -String 'ThisIsANiceString' | Should -Be 'VGhpc0lzQU5pY2VTdHJpbmc='
}

It "'Hello World' | ConvertTo-Base64 -> SGVsbG8gV29ybGQ=" {
'Hello World' | ConvertTo-Base64 | Should -Be 'SGVsbG8gV29ybGQ='
}
}
It 'Function: Set-PSModuleTest' {
Set-PSModuleTest -Name 'World' | Should -Be 'Hello, World!'
}
It 'Function: Test-PSModuleTest' {
Test-PSModuleTest -Name 'World' | Should -Be 'Hello, World!'
Context 'Function: ConvertFrom-Base64' {
It "ConvertFrom-Base64 -Base64String 'VGhpc0lzQU5pY2VTdHJpbmc=' -> ThisIsANiceString" {
ConvertFrom-Base64 -Base64String 'VGhpc0lzQU5pY2VTdHJpbmc=' | Should -Be 'ThisIsANiceString'
}

It "'SGVsbG8gV29ybGQ=' | ConvertFrom-Base64 -> Hello World" {
'SGVsbG8gV29ybGQ=' | ConvertFrom-Base64 | Should -Be 'Hello World'
}
}
}