Skip to content

Commit f7ce675

Browse files
committed
md5/sha256 now should work in browsers
fixes #4
1 parent 0dc6140 commit f7ce675

File tree

7 files changed

+32
-18
lines changed

7 files changed

+32
-18
lines changed

.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
#js ./ref.js > A.ref
4+
#js ./sha256c.js > B.me
5+
#
6+
#diff --width 35 -y A.ref B.me | less
7+
8+
node2vim.sh js cry/sha256c.js
9+
node2vim.sh js cry/md5c.js
10+

cry/md5.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// script babel.sh
44
// GIT https://github.com/hilbix/js.git
55
// branch es13dev
6-
// src f7e6f0fe28f31182c91d3e51678b1644c67907ca39138028fb1f2f84f4233a6c cry/md5c.js
6+
// src 2cfb53e0374f5672d85dd0e9eae0fcb2edf516abeab4319a47d87fb1cd16d734 cry/md5c.js
77
// DEBUG <script src="cry/md5.js" data-debug></script>
88
require = (function(orig,cs, _)
99
{
@@ -98,7 +98,7 @@ module.exports = _typeof;
9898
});
9999
// BABEL babeljs --source-type=script --presets @babel/preset-env --plugins @babel/plugin-proposal-optional-chaining,@babel/plugin-proposal-class-properties,@babel/plugin-transform-runtime cry/md5c.js
100100
// DO NOT EDIT. Automatically generated by ./unroll.sh md5c.js.in
101-
// src 612ab73fb2803a549707eaa3671847916baca09579e48cafe6d7d8ace330e0fa md5c.js.in
101+
// src 20d6e36f4302f946e9844e613f1ecb173ea05b49a5e93934096b51dcf0b6e1f7 md5c.js.in
102102
'use strict'; // This is free as in free beer, free speech and free baby.
103103
// IMPORTANT! NEVER COVER THIS CODE WITH A COPYRIGHT
104104
// as this would break German Urheberrecht!
@@ -409,12 +409,14 @@ var MD5 = function (_) {
409409
}, {
410410
key: "$bin",
411411
get: function get() {
412-
return new Uint8Array(this.buf);
412+
return new Uint8Array(this.buf.buffer);
413413
}
414414
}, {
415415
key: "$hex",
416416
get: function get() {
417-
return Buffer.from(this.buf.buffer).toString('hex');
417+
return Array.from(this.$bin, function (b) {
418+
return b.toString(16).padStart(2, '0');
419+
}).join('');
418420
}
419421
}], [{
420422
key: "md5",

cry/md5c.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// DO NOT EDIT. Automatically generated by ./unroll.sh md5c.js.in
2-
// src 612ab73fb2803a549707eaa3671847916baca09579e48cafe6d7d8ace330e0fa md5c.js.in
2+
// src 20d6e36f4302f946e9844e613f1ecb173ea05b49a5e93934096b51dcf0b6e1f7 md5c.js.in
33
'use strict';
44
// This is free as in free beer, free speech and free baby.
55
// IMPORTANT! NEVER COVER THIS CODE WITH A COPYRIGHT
@@ -271,11 +271,11 @@ ctx[3] = d + ctx[3] | 0;
271271
}
272272
get $bin()
273273
{
274-
return new Uint8Array(this.buf);
274+
return new Uint8Array(this.buf.buffer);
275275
}
276276
get $hex()
277277
{
278-
return Buffer.from(this.buf.buffer).toString('hex');
278+
return Array.from(this.$bin, b => b.toString(16).padStart(2, '0')).join('');
279279
}
280280
static md5(s,bin)
281281
{

cry/sha256.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// script babel.sh
44
// GIT https://github.com/hilbix/js.git
55
// branch es13dev
6-
// src d78239aa6c6c2c41b21b1103983d5acab0a5332332b7734529c58c5ebbc73bf0 cry/sha256c.js
6+
// src a38aec76568e74c50dcafd9bbabcb1f6cd0a13c76d48745ede261b993946db52 cry/sha256c.js
77
// DEBUG <script src="cry/sha256.js" data-debug></script>
88
require = (function(orig,cs, _)
99
{
@@ -98,7 +98,7 @@ module.exports = _typeof;
9898
});
9999
// BABEL babeljs --source-type=script --presets @babel/preset-env --plugins @babel/plugin-proposal-optional-chaining,@babel/plugin-proposal-class-properties,@babel/plugin-transform-runtime cry/sha256c.js
100100
// DO NOT EDIT. Automatically generated by ./unroll.sh sha256c.js.in
101-
// src 841241e5be570e4e8c835af1fd1ffa803b727b4f24ee511e1390c6b3be404cdc sha256c.js.in
101+
// src 4e176d6dd957b9f0e2b50a8c1c63f7fa9bc2f7a29de935ffa35c4e84ed9aafb5 sha256c.js.in
102102
'use strict'; // This is free as in free beer, free speech and free baby.
103103
// IMPORTANT! NEVER COVER THIS CODE WITH A COPYRIGHT
104104
// as this might break German Urheberrecht!
@@ -548,12 +548,14 @@ var SHA256 = function (_) {
548548
}, {
549549
key: "$bin",
550550
get: function get() {
551-
return new Uint8Array(this.buf);
551+
return new Uint8Array(this.buf.buffer);
552552
}
553553
}, {
554554
key: "$hex",
555555
get: function get() {
556-
return Buffer.from(this.buf.buffer).toString('hex');
556+
return Array.from(this.$bin, function (b) {
557+
return b.toString(16).padStart(2, '0');
558+
}).join('');
557559
}
558560
}], [{
559561
key: "sha256",

cry/sha256c.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// DO NOT EDIT. Automatically generated by ./unroll.sh sha256c.js.in
2-
// src 841241e5be570e4e8c835af1fd1ffa803b727b4f24ee511e1390c6b3be404cdc sha256c.js.in
2+
// src 4e176d6dd957b9f0e2b50a8c1c63f7fa9bc2f7a29de935ffa35c4e84ed9aafb5 sha256c.js.in
33
'use strict';
44
// This is free as in free beer, free speech and free baby.
55
// IMPORTANT! NEVER COVER THIS CODE WITH A COPYRIGHT
@@ -417,11 +417,11 @@ ctx[7] = ctx[7] + h | 0;
417417
}
418418
get $bin()
419419
{
420-
return new Uint8Array(this.buf);
420+
return new Uint8Array(this.buf.buffer);
421421
}
422422
get $hex()
423423
{
424-
return Buffer.from(this.buf.buffer).toString('hex');
424+
return Array.from(this.$bin, b => b.toString(16).padStart(2, '0')).join('');
425425
}
426426
static sha256(s,bin)
427427
{

md5c.js.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,11 @@ const MD5 = (_=>_())(() => {
274274
}
275275
get $bin()
276276
{
277-
return new Uint8Array(this.buf);
277+
return new Uint8Array(this.buf.buffer);
278278
}
279279
get $hex()
280280
{
281-
return Buffer.from(this.buf.buffer).toString('hex');
281+
return Array.from(this.$bin, b => b.toString(16).padStart(2, '0')).join('');
282282
}
283283
static md5(s,bin)
284284
{

sha256c.js.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,11 @@ const SHA256 = (_=>_())(() => {
300300
}
301301
get $bin()
302302
{
303-
return new Uint8Array(this.buf);
303+
return new Uint8Array(this.buf.buffer);
304304
}
305305
get $hex()
306306
{
307-
return Buffer.from(this.buf.buffer).toString('hex');
307+
return Array.from(this.$bin, b => b.toString(16).padStart(2, '0')).join('');
308308
}
309309
static sha256(s,bin)
310310
{

0 commit comments

Comments
 (0)