Debian Codegraph @

lib/ansible/executor/powershell/winrm_put_file.ps1

raw
1 # (c) 2025 Ansible Project
2 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
3
4 using namespace System.IO
5 using namespace System.Security.Cryptography
6
7 [CmdletBinding()]
8 param (
9 [Parameter(Mandatory)]
10 [string]
11 $Path,
12
13 [Parameter(ValueFromPipeline)]
14 [string]
15 $InputObject
16 )
17
18 begin {
19 $fd = [File]::Create($Path)
20 $sha1 = [SHA1]::Create()
21 $bytes = @() #initialize for empty file case
22 }
23
24 process {
25 $bytes = [Convert]::FromBase64String($InputObject)
26 $null = $sha1.TransformBlock($bytes, 0, $bytes.Length, $bytes, 0)
27 $fd.Write($bytes, 0, $bytes.Length)
28 }
29
30 end {
31 $fd.Dispose()
32 $null = $sha1.TransformFinalBlock($bytes, 0, 0)
33 $hash = [BitConverter]::ToString($sha1.Hash).Replace("-", "").ToLowerInvariant()
34
35 '{{"sha1":"{0}"}}' -f $hash
36 }