{"version":3,"sources":["../../../packages/core/data/powershell-crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAM,MAAM,MAAM,CAAC;AAItC,OAAO,EAAc,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D;;;GAGG;AACH,qBAAa,gBAAgB;IAEzB;;;;;;OAMG;IAEH;;;;;;OAMG;WACY,wBAAwB,CACnC,oBAAoB,EAAE,oBAAoB,EAC1C,iBAAiB,EAAE,iBAAiB,GAAG,UAAU,CAAC,MAAM,CAAC;IAM7D;;;;;;;OAOG;WACW,uBAAuB,CACjC,oBAAoB,EAAE,oBAAoB,EAC1C,iBAAiB,EAAE,iBAAiB,EACpC,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;CAYxC","file":"powershell-crypto.d.ts","sourcesContent":["import { Observable, of } from 'rxjs';\r\nimport { map, mergeMap } from 'rxjs/operators';\r\nimport { PowerShellScripts } from '../generated/powershell-scripts';\r\nimport { Crypto } from './crypto';\r\nimport { PowerShell, PowerShellSession } from './powershell';\r\nimport { PowerShellConnection } from './powershell-connection';\r\n\r\n/**\r\n * powerShellCrypto Crypto interface class.\r\n * @dynamic\r\n */\r\nexport class PowerShellCrypto {\r\n\r\n    /**\r\n     * encrypt with RSA/SHA-1\r\n     *\r\n     * @param jwk the JSON Web Key. Single string with JSON.stringify format.\r\n     * @param data the original data to hash.\r\n     * @return Observable<string> the hash generated.\r\n     */\r\n\r\n    /**\r\n     * Creates an RSAProvider or reuses a cached one on a node and returns its JSON Web Key string\r\n     *\r\n     * @param powerShellConnection the established powerShell connection to the node\r\n     * @param powerShellSession the established powerShell session with the node\r\n     * @return Observable<string> the jwk string.\r\n     */\r\n     public static getEncryptionJWKFromNode(\r\n        powerShellConnection: PowerShellConnection,\r\n        powerShellSession: PowerShellSession): Observable<string> {\r\n        const getJWKCommand = PowerShell.createCommand(PowerShellScripts.Get_EncryptionJWKOnNode);\r\n        return powerShellConnection.run(powerShellSession, getJWKCommand, { logTelemetry: true })\r\n            .pipe(map(jwk => jwk.results));\r\n    }\r\n\r\n    /**\r\n     * Creates an RSAProvider or reuses a cached one on a node and uses its jwk to encrypt data\r\n     *\r\n     * @param powerShellConnection the established powerShell connection to the node\r\n     * @param powerShellSession the established powerShell session with the node\r\n     * @param data string data to be encrypted\r\n     * @return Observable<string> the encrypted data or null if data is null.\r\n     */\r\n    public static encryptDataUsingNodeJWK(\r\n        powerShellConnection: PowerShellConnection,\r\n        powerShellSession: PowerShellSession,\r\n        data: string): Observable<string> {\r\n\r\n        if (data != null && data.length > 0) {\r\n            return PowerShellCrypto.getEncryptionJWKFromNode(powerShellConnection, powerShellSession)\r\n            .pipe(mergeMap(jwk => Crypto.encryptRsaSha1(jwk, data)));\r\n        } else {\r\n            // Simply return an observable with a null string if the passed in data is null.\r\n            // The will make password optional scenarios more idiomatic since iif() will not be\r\n            // needed to build a different observable when the password is optional to the command.\r\n            return of(data);\r\n        }\r\n    }\r\n}\r\n"]}