mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 14:20:12 +00:00
Add mcrypt@0.1
This commit is contained in:
31
types/mcrypt/index.d.ts
vendored
Normal file
31
types/mcrypt/index.d.ts
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
// Type definitions for mcrypt 0.1
|
||||
// Project: https://github.com/tugrul/node-mcrypt
|
||||
// Definitions by: Alan Plum <https://github.com/pluma>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.1
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
export function getAlgorithmNames(): string[];
|
||||
export function getModeNames(): string[];
|
||||
|
||||
export class MCrypt {
|
||||
constructor(algorithm: string, mode: string);
|
||||
open(key: string | Buffer, iv?: string | Buffer): void;
|
||||
encrypt(plaintext: string | Buffer): Buffer;
|
||||
decrypt(ciphertext: Buffer): Buffer;
|
||||
generateIv(): Buffer;
|
||||
validateKeySize(validate: boolean): void;
|
||||
validateIvSize(validate: boolean): void;
|
||||
selfTest(): boolean;
|
||||
isBlockAlgorithmMode(): boolean;
|
||||
isBlockAlgorithm(): boolean;
|
||||
isBlockMode(): boolean;
|
||||
getBlockSize(): number;
|
||||
getKeySize(): number;
|
||||
getSupportedKeySizes(): number[];
|
||||
getIvSize(): number;
|
||||
hasIv(): boolean;
|
||||
getAlgorithmName(): string;
|
||||
getModeName(): string;
|
||||
}
|
||||
51
types/mcrypt/mcrypt-tests.ts
Normal file
51
types/mcrypt/mcrypt-tests.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { getAlgorithmNames, getModeNames, MCrypt } from "mcrypt";
|
||||
|
||||
let plaintext: Buffer;
|
||||
let ciphertext: Buffer;
|
||||
|
||||
for (const algo of getAlgorithmNames()) {
|
||||
console.log(algo.toUpperCase());
|
||||
}
|
||||
for (const mode of getModeNames()) {
|
||||
console.log(mode.toUpperCase());
|
||||
}
|
||||
|
||||
const desEcb = new MCrypt("des", "ecb");
|
||||
desEcb.open("madepass");
|
||||
|
||||
ciphertext = desEcb.encrypt("too many secrets");
|
||||
console.log(ciphertext.toString("base64"));
|
||||
|
||||
plaintext = desEcb.decrypt(ciphertext);
|
||||
console.log(plaintext.toString());
|
||||
|
||||
const blowfishCfb = new MCrypt("blowfish", "cfb");
|
||||
const iv = blowfishCfb.generateIv();
|
||||
blowfishCfb.open("somekey", iv);
|
||||
ciphertext = blowfishCfb.encrypt("sometext");
|
||||
console.log(Buffer.concat([iv, ciphertext]).toString("base64"));
|
||||
|
||||
const bfEcb = new MCrypt("blowfish", "ecb");
|
||||
bfEcb.validateKeySize(false);
|
||||
bfEcb.open("typeconfig.sys^_-");
|
||||
|
||||
const rjCbc = new MCrypt("rijndael-256", "cbc");
|
||||
rjCbc.validateIvSize(false);
|
||||
rjCbc.open("$verysec$retkey$", "foobar");
|
||||
|
||||
console.log(blowfishCfb.getBlockSize() * 8);
|
||||
console.log(blowfishCfb.getKeySize() * 8);
|
||||
console.log(blowfishCfb.getSupportedKeySizes().map(v => v * 8));
|
||||
console.log(blowfishCfb.getIvSize() * 8);
|
||||
console.log(blowfishCfb.getAlgorithmName().toUpperCase());
|
||||
console.log(blowfishCfb.getModeName().toUpperCase());
|
||||
|
||||
function assertBool(value: boolean) {
|
||||
return value;
|
||||
}
|
||||
|
||||
assertBool(blowfishCfb.selfTest());
|
||||
assertBool(blowfishCfb.isBlockAlgorithmMode());
|
||||
assertBool(blowfishCfb.isBlockAlgorithm());
|
||||
assertBool(blowfishCfb.isBlockMode());
|
||||
assertBool(blowfishCfb.hasIv());
|
||||
16
types/mcrypt/tsconfig.json
Normal file
16
types/mcrypt/tsconfig.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": ["index.d.ts", "mcrypt-tests.ts"]
|
||||
}
|
||||
1
types/mcrypt/tslint.json
Normal file
1
types/mcrypt/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user