94 lines
2.2 KiB
Plaintext
94 lines
2.2 KiB
Plaintext
exports[`test crypto.js 1`] = `
|
|
"/* @flow */
|
|
|
|
const crypto = require(\'crypto\');
|
|
|
|
let tests = [
|
|
// Hmac is a duplex stream
|
|
function() {
|
|
const hmac = crypto.createHmac(\'sha256\', \'a secret\');
|
|
|
|
hmac.on(\'readable\', () => {
|
|
(hmac.read(): ?(string | Buffer));
|
|
(hmac.read(): number); // 4 errors: null, void, string, Buffer
|
|
});
|
|
|
|
hmac.write(\'some data to hash\');
|
|
hmac.write(123); // 2 errors: not a string or a Buffer
|
|
hmac.end();
|
|
},
|
|
|
|
// Hmac supports update and digest functions too
|
|
function(buf: Buffer) {
|
|
const hmac = crypto.createHmac(\'sha256\', \'a secret\');
|
|
|
|
hmac.update(\'some data to hash\');
|
|
hmac.update(\'foo\', \'utf8\');
|
|
hmac.update(\'foo\', \'bogus\'); // 1 error
|
|
hmac.update(buf);
|
|
hmac.update(buf, \'utf8\'); // 1 error: no encoding when passing a buffer
|
|
|
|
// it\'s also chainable
|
|
(hmac.update(\'some data to hash\').update(buf).digest(): Buffer);
|
|
|
|
(hmac.digest(\'hex\'): string);
|
|
(hmac.digest(): Buffer);
|
|
(hmac.digest(\'hex\'): void); // 1 error
|
|
(hmac.digest(): void); // 1 error
|
|
}
|
|
]
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
/* @flow */
|
|
// Hmac is a duplex stream
|
|
// 4 errors: null, void, string, Buffer
|
|
// 2 errors: not a string or a Buffer
|
|
// Hmac supports update and digest functions too
|
|
// 1 error
|
|
// 1 error: no encoding when passing a buffer
|
|
// it\'s also chainable
|
|
// 1 error
|
|
// 1 error
|
|
const crypto = require(\"crypto\");
|
|
let tests = [
|
|
function() {
|
|
const hmac = crypto.createHmac(\"sha256\", \"a secret\");
|
|
|
|
hmac.on(\"readable\", () => {
|
|
(hmac.read(): ?(string | Buffer));
|
|
|
|
(hmac.read(): number);
|
|
});
|
|
|
|
hmac.write(\"some data to hash\");
|
|
|
|
hmac.write(123);
|
|
|
|
hmac.end();
|
|
},
|
|
function(buf: Buffer) {
|
|
const hmac = crypto.createHmac(\"sha256\", \"a secret\");
|
|
|
|
hmac.update(\"some data to hash\");
|
|
|
|
hmac.update(\"foo\", \"utf8\");
|
|
|
|
hmac.update(\"foo\", \"bogus\");
|
|
|
|
hmac.update(buf);
|
|
|
|
hmac.update(buf, \"utf8\");
|
|
|
|
(hmac.update(\"some data to hash\").update(buf).digest(): Buffer);
|
|
|
|
(hmac.digest(\"hex\"): string);
|
|
|
|
(hmac.digest(): Buffer);
|
|
|
|
(hmac.digest(\"hex\"): void);
|
|
|
|
(hmac.digest(): void);
|
|
}
|
|
];
|
|
"
|
|
`;
|