0
0

增加了git功能,但是还未完善

This commit is contained in:
xubing
2025-11-24 17:53:48 +08:00
parent 925024bce1
commit fa1e291bed
682 changed files with 131314 additions and 157 deletions

80
node_modules/sha.js/test/hash.js generated vendored Normal file
View File

@@ -0,0 +1,80 @@
'use strict';
var tape = require('tape');
var Buffer = require('safe-buffer').Buffer;
var Hash = require('../hash');
var hex = '0A1B2C3D4E5F6G7H';
function equal(t, a, b) {
t.equal(a.length, b.length);
t.equal(a.toString('hex'), b.toString('hex'));
}
var hexBuf = Buffer.from('0A1B2C3D4E5F6G7H', 'utf8');
var count16 = {
strings: ['0A1B2C3D4E5F6G7H'],
buffers: [
hexBuf,
Buffer.from('80000000000000000000000000000080', 'hex')
]
};
var empty = {
strings: [''],
buffers: [
Buffer.from('80000000000000000000000000000000', 'hex')
]
};
var multi = {
strings: ['abcd', 'efhijk', 'lmnopq'],
buffers: [
Buffer.from('abcdefhijklmnopq', 'ascii'),
Buffer.from('80000000000000000000000000000080', 'hex')
]
};
var long = {
strings: [hex + hex],
buffers: [
hexBuf,
hexBuf,
Buffer.from('80000000000000000000000000000100', 'hex')
]
};
function makeTest(name, data) {
tape(name, function (t) {
var h = new Hash(16, 8);
var hash = Buffer.alloc(20);
var n = 2;
var expected = data.buffers.slice();
// t.plan(expected.length + 1)
h._update = function (block) {
var e = expected.shift();
equal(t, block, e);
if (n < 0) {
throw new Error('expecting only 2 calls to _update');
}
};
h._hash = function () {
return hash;
};
data.strings.forEach(function (string) {
h.update(string, 'ascii');
});
equal(t, h.digest(), hash);
t.end();
});
}
makeTest('Hash#update 1 in 1', count16);
makeTest('empty Hash#update', empty);
makeTest('Hash#update 1 in 3', multi);
makeTest('Hash#update 2 in 1', long);

138
node_modules/sha.js/test/test.js generated vendored Normal file
View File

@@ -0,0 +1,138 @@
'use strict';
var crypto = require('crypto');
var tape = require('tape');
var Buffer = require('safe-buffer').Buffer;
var Sha1 = require('../').sha1;
var nodeSupportsUint16 = false;
try {
crypto.createHash('sha1').update(new Uint16Array());
nodeSupportsUint16 = true;
} catch (err) {}
var inputs = [
['', 'ascii'],
['abc', 'ascii'],
['123', 'ascii'],
['123456789abcdef123456789abcdef123456789abcdef123456789abcdef', 'ascii'],
['123456789abcdef123456789abcdef123456789abcdef123456789abc', 'ascii'],
['123456789abcdef123456789abcdef123456789abcdef123456789ab', 'ascii'],
['0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde', 'ascii'],
['0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef', 'ascii'],
['foobarbaz', 'ascii'],
[Buffer.from('buffer')],
nodeSupportsUint16 ? [new Uint16Array([1, 2, 3])] : null
].filter(Boolean);
tape("hash is the same as node's crypto", function (t) {
inputs.forEach(function (v) {
var a = new Sha1().update(v[0], v[1]).digest('hex');
var e = crypto.createHash('sha1').update(v[0], v[1]).digest('hex');
t.equal(a, e, a + ' == ' + e);
});
t.end();
});
tape('call update multiple times', function (t) {
inputs.forEach(function (v) {
var hash = new Sha1();
var sha1hash = crypto.createHash('sha1');
for (var i = 0; i < v[0].length; i = (i + 1) * 2) {
var s = v[0].slice(i, (i + 1) * 2);
hash.update(s, v[1]);
sha1hash.update(s, v[1]);
}
var a = hash.digest('hex');
var e = sha1hash.digest('hex');
t.equal(a, e, a + ' == ' + e);
});
t.end();
});
tape('call update twice', function (t) {
var sha1hash = crypto.createHash('sha1');
var hash = new Sha1();
sha1hash.update('foo', 'ascii');
hash.update('foo', 'ascii');
sha1hash.update('bar', 'ascii');
hash.update('bar', 'ascii');
sha1hash.update('baz', 'ascii');
hash.update('baz', 'ascii');
var a = hash.digest('hex');
var e = sha1hash.digest('hex');
t.equal(a, e);
t.end();
});
tape('hex encoding', function (t) {
inputs.forEach(function (v) {
var hash = new Sha1();
var sha1hash = crypto.createHash('sha1');
for (var i = 0; i < v[0].length; i = (i + 1) * 2) {
var s = v[0].slice(i, (i + 1) * 2);
hash.update(Buffer.from(s, 'ascii').toString('hex'), 'hex');
sha1hash.update(Buffer.from(s, 'ascii').toString('hex'), 'hex');
}
var a = hash.digest('hex');
var e = sha1hash.digest('hex');
t.equal(a, e, a + ' == ' + e);
});
t.end();
});
tape('throws on invalid input', function (t) {
var invalid = [
{}, // non-arrayish
{ length: 20 }, // undefined values
[NaN], // non-numbers
[[]], // non-numbers
[1, 1.5], // non-integers
[1, 256], // out of bounds
[-1, 0] // out of bounds
];
invalid.forEach(function (input) {
var hash = new Sha1();
t['throws'](function () {
hash.update(input);
hash.digest('hex');
});
});
t.end();
});
tape('call digest for more than MAX_UINT32 bits of data', function (t) {
var sha1hash = crypto.createHash('sha1');
var hash = new Sha1();
var bigData;
try {
bigData = Buffer.alloc(0x1ffffffff / 8);
} catch (err) {
// node < 3 has a lower buffer size limit than node 3+. node 0.10 requires the `/8`, 0.12 - 2 are fine with `-8`
bigData = Buffer.alloc(0x3fffffff / 8);
}
hash.update(bigData);
sha1hash.update(bigData);
var a = hash.digest('hex');
var e = sha1hash.digest('hex');
t.equal(a, e, a + ' == ' + e);
t.end();
});

72
node_modules/sha.js/test/vectors.js generated vendored Normal file
View File

@@ -0,0 +1,72 @@
'use strict';
var tape = require('tape');
var vectors = require('hash-test-vectors');
// var from = require('bops/typedarray/from')
var Buffer = require('safe-buffer').Buffer;
var createHash = require('../');
function makeTest(alg, i, verbose) {
var v = vectors[i];
tape(alg + ': NIST vector ' + i, function (t) {
if (verbose) {
t.comment(v);
t.comment('VECTOR', i);
t.comment('INPUT', v.input);
t.comment(Buffer.from(v.input, 'base64').toString('hex'));
}
var buf = Buffer.from(v.input, 'base64');
t.equal(createHash(alg).update(buf).digest('hex'), v[alg]);
// eslint-disable-next-line no-param-reassign
i = ~~(buf.length / 2);
var buf1 = buf.slice(0, i);
var buf2 = buf.slice(i, buf.length);
t.comment(buf1.length + ', ' + buf2.length + ', ' + buf.length);
t.comment(createHash(alg)._block.length);
t.equal(
createHash(alg)
.update(buf1)
.update(buf2)
.digest('hex'),
v[alg]
);
var j, buf3;
// eslint-disable-next-line no-param-reassign
i = ~~(buf.length / 3);
j = ~~(buf.length * 2 / 3);
buf1 = buf.slice(0, i);
buf2 = buf.slice(i, j);
buf3 = buf.slice(j, buf.length);
t.equal(
createHash(alg)
.update(buf1)
.update(buf2)
.update(buf3)
.digest('hex'),
v[alg]
);
setTimeout(function () {
// avoid "too much recursion" errors in tape in firefox
t.end();
});
});
}
vectors.forEach(function (v, i) {
makeTest('sha', i);
makeTest('sha1', i);
makeTest('sha224', i);
makeTest('sha256', i);
makeTest('sha384', i);
makeTest('sha512', i);
});