The Standard Library has been moved to JSR. See the blog post for details.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.// Copyright Joyent, Inc. and Node.js contributors. All rights reserved. MIT license.
import { ERR_INVALID_ARG_TYPE } from "../errors.ts";import { validateInt32, validateObject } from "../validators.mjs";import { Buffer } from "../../buffer.ts";import { notImplemented } from "../../_utils.ts";import type { TransformOptions } from "../../_stream.d.ts";import { Transform } from "../../_stream.mjs";import { KeyObject } from "./keys.ts";import type { BufferEncoding } from "../../_global.d.ts";import type { BinaryLike, Encoding } from "./types.ts";import { privateDecrypt, privateEncrypt, publicDecrypt, publicEncrypt,} from "../../_crypto/crypto_browserify/public_encrypt/mod.js";
export { privateDecrypt, privateEncrypt, publicDecrypt, publicEncrypt,} from "../../_crypto/crypto_browserify/public_encrypt/mod.js";
export type CipherCCMTypes = | "aes-128-ccm" | "aes-192-ccm" | "aes-256-ccm" | "chacha20-poly1305";export type CipherGCMTypes = "aes-128-gcm" | "aes-192-gcm" | "aes-256-gcm";export type CipherOCBTypes = "aes-128-ocb" | "aes-192-ocb" | "aes-256-ocb";
export type CipherKey = BinaryLike | KeyObject;
export interface CipherCCMOptions extends TransformOptions { authTagLength: number;}
export interface CipherGCMOptions extends TransformOptions { authTagLength?: number | undefined;}
export interface CipherOCBOptions extends TransformOptions { authTagLength: number;}
export interface Cipher extends Transform { update(data: BinaryLike): Buffer; update(data: string, inputEncoding: Encoding): Buffer; update( data: ArrayBufferView, inputEncoding: undefined, outputEncoding: Encoding, ): string; update( data: string, inputEncoding: Encoding | undefined, outputEncoding: Encoding, ): string;
final(): Buffer; final(outputEncoding: BufferEncoding): string;
setAutoPadding(autoPadding?: boolean): this;}
export type Decipher = Cipher;
export interface CipherCCM extends Cipher { setAAD( buffer: ArrayBufferView, options: { plaintextLength: number; }, ): this; getAuthTag(): Buffer;}
export interface CipherGCM extends Cipher { setAAD( buffer: ArrayBufferView, options?: { plaintextLength: number; }, ): this; getAuthTag(): Buffer;}
export interface CipherOCB extends Cipher { setAAD( buffer: ArrayBufferView, options?: { plaintextLength: number; }, ): this; getAuthTag(): Buffer;}
export interface DecipherCCM extends Decipher { setAuthTag(buffer: ArrayBufferView): this; setAAD( buffer: ArrayBufferView, options: { plaintextLength: number; }, ): this;}
export interface DecipherGCM extends Decipher { setAuthTag(buffer: ArrayBufferView): this; setAAD( buffer: ArrayBufferView, options?: { plaintextLength: number; }, ): this;}
export interface DecipherOCB extends Decipher { setAuthTag(buffer: ArrayBufferView): this; setAAD( buffer: ArrayBufferView, options?: { plaintextLength: number; }, ): this;}
export class Cipheriv extends Transform implements Cipher { constructor( _cipher: string, _key: CipherKey, _iv: BinaryLike | null, _options?: TransformOptions, ) { super();
notImplemented("crypto.Cipheriv"); }
final(): Buffer; final(outputEncoding: BufferEncoding): string; final(_outputEncoding?: string): Buffer | string { notImplemented("crypto.Cipheriv.prototype.final"); }
getAuthTag(): Buffer { notImplemented("crypto.Cipheriv.prototype.getAuthTag"); }
setAAD( _buffer: ArrayBufferView, _options?: { plaintextLength: number; }, ): this { notImplemented("crypto.Cipheriv.prototype.setAAD"); }
setAutoPadding(_autoPadding?: boolean): this { notImplemented("crypto.Cipheriv.prototype.setAutoPadding"); }
update(data: BinaryLike): Buffer; update(data: string, inputEncoding: Encoding): Buffer; update( data: ArrayBufferView, inputEncoding: undefined, outputEncoding: Encoding, ): string; update( data: string, inputEncoding: Encoding | undefined, outputEncoding: Encoding, ): string; update( _data: string | BinaryLike | ArrayBufferView, _inputEncoding?: Encoding, _outputEncoding?: Encoding, ): Buffer | string { notImplemented("crypto.Cipheriv.prototype.update"); }}
export class Decipheriv extends Transform implements Cipher { constructor( _cipher: string, _key: CipherKey, _iv: BinaryLike | null, _options?: TransformOptions, ) { super();
notImplemented("crypto.Decipheriv"); }
final(): Buffer; final(outputEncoding: BufferEncoding): string; final(_outputEncoding?: string): Buffer | string { notImplemented("crypto.Decipheriv.prototype.final"); }
setAAD( _buffer: ArrayBufferView, _options?: { plaintextLength: number; }, ): this { notImplemented("crypto.Decipheriv.prototype.setAAD"); }
setAuthTag(_buffer: BinaryLike, _encoding?: string): this { notImplemented("crypto.Decipheriv.prototype.setAuthTag"); }
setAutoPadding(_autoPadding?: boolean): this { notImplemented("crypto.Decipheriv.prototype.setAutoPadding"); }
update(data: BinaryLike): Buffer; update(data: string, inputEncoding: Encoding): Buffer; update( data: ArrayBufferView, inputEncoding: undefined, outputEncoding: Encoding, ): string; update( data: string, inputEncoding: Encoding | undefined, outputEncoding: Encoding, ): string; update( _data: string | BinaryLike | ArrayBufferView, _inputEncoding?: Encoding, _outputEncoding?: Encoding, ): Buffer | string { notImplemented("crypto.Decipheriv.prototype.update"); }}
export function getCipherInfo( nameOrNid: string | number, options?: { keyLength?: number; ivLength?: number },) { if (typeof nameOrNid !== "string" && typeof nameOrNid !== "number") { throw new ERR_INVALID_ARG_TYPE( "nameOrNid", ["string", "number"], nameOrNid, ); }
if (typeof nameOrNid === "number") { validateInt32(nameOrNid, "nameOrNid"); }
let keyLength, ivLength;
if (options !== undefined) { validateObject(options, "options");
({ keyLength, ivLength } = options);
if (keyLength !== undefined) { validateInt32(keyLength, "options.keyLength"); }
if (ivLength !== undefined) { validateInt32(ivLength, "options.ivLength"); } }
notImplemented("crypto.getCipherInfo");}
export default { privateDecrypt, privateEncrypt, publicDecrypt, publicEncrypt, Cipheriv, Decipheriv, getCipherInfo,};