( name: string, to: To, format: KeyFormat_.Format<R, "decode", Data>, decode: (data: Data) => Effect.Effect<To["Type"], CryptoError_.CryptoError>, canEncode: boolean )
| 14515 | (format._tag === "jwk" ? CryptoJsonWebKey : format.pem ? String : Uint8Array) as Codec<any> |
| 14516 | |
| 14517 | const cryptoKeyFromFormat = <To extends Codec<any>, R extends KeyFormat_.Role, Data>( |
| 14518 | name: string, |
| 14519 | to: To, |
| 14520 | format: KeyFormat_.Format<R, "decode", Data>, |
| 14521 | decode: (data: Data) => Effect.Effect<To["Type"], CryptoError_.CryptoError>, |
| 14522 | canEncode: boolean |
| 14523 | ): decodeTo<To, Codec<Data>> => { |
| 14524 | // PKCS#1 and SEC1 are read only. |
| 14525 | const writable = canEncode && format._tag !== "pkcs1" && format._tag !== "sec1" |
| 14526 | return cryptoFormatData(format).pipe(decodeTo( |
| 14527 | to, |
| 14528 | SchemaTransformation.transformEffect<To["Type"], Data>({ |
| 14529 | decode: (data, options) => |
| 14530 | // Secret JWK decoding is synchronous, but all format schemas are async-only. |
| 14531 | Effect.flatMap(Effect.promise(() => Promise.resolve()), () => |
| 14532 | Effect.mapError(decode(data), (error) => cryptoIssue(error, data, options))), |
| 14533 | encode: (key, options) => |
| 14534 | writable |
| 14535 | ? Effect.mapError( |
| 14536 | KeyFormat_.encode(format as any, key as KeyFormat_.Key) as Effect.Effect<Data, CryptoError_.CryptoError>, |
| 14537 | (error) => cryptoIssue(error, key, options) |
| 14538 | ) |
| 14539 | : cryptoForbiddenEncode(name, key, options) |
| 14540 | }) |
| 14541 | )) |
| 14542 | } |
| 14543 | |
| 14544 | /** |
| 14545 | * Type-level representation of {@link MacKey}. |
no test coverage detected