diff options
author | Minteck <contact@minteck.org> | 2022-08-10 10:38:44 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-08-10 10:38:44 +0200 |
commit | c6dbf0450566c40efc4a26f4f0717452b6ef95cd (patch) | |
tree | b4be2d508223820d0a77d5a3e35e82684da3b6ec /node_modules/thirty-two | |
download | hornchat-mane.tar.gz hornchat-mane.tar.bz2 hornchat-mane.zip |
Diffstat (limited to 'node_modules/thirty-two')
-rw-r--r-- | node_modules/thirty-two/.npmignore | 4 | ||||
-rw-r--r-- | node_modules/thirty-two/LICENSE.txt | 19 | ||||
-rw-r--r-- | node_modules/thirty-two/Makefile | 24 | ||||
-rw-r--r-- | node_modules/thirty-two/README.md | 15 | ||||
-rw-r--r-- | node_modules/thirty-two/index.js | 23 | ||||
-rw-r--r-- | node_modules/thirty-two/lib/thirty-two/index.js | 26 | ||||
-rw-r--r-- | node_modules/thirty-two/lib/thirty-two/thirty-two.js | 128 | ||||
-rw-r--r-- | node_modules/thirty-two/package.json | 15 | ||||
-rw-r--r-- | node_modules/thirty-two/spec/thirty-two_spec.js | 63 |
9 files changed, 317 insertions, 0 deletions
diff --git a/node_modules/thirty-two/.npmignore b/node_modules/thirty-two/.npmignore new file mode 100644 index 0000000..3ee8de4 --- /dev/null +++ b/node_modules/thirty-two/.npmignore @@ -0,0 +1,4 @@ +*.kpf +*~ +\#* +node_modules diff --git a/node_modules/thirty-two/LICENSE.txt b/node_modules/thirty-two/LICENSE.txt new file mode 100644 index 0000000..364e7fa --- /dev/null +++ b/node_modules/thirty-two/LICENSE.txt @@ -0,0 +1,19 @@ +Copyright (c) 2011, Chris Umbel + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE.
\ No newline at end of file diff --git a/node_modules/thirty-two/Makefile b/node_modules/thirty-two/Makefile new file mode 100644 index 0000000..6011230 --- /dev/null +++ b/node_modules/thirty-two/Makefile @@ -0,0 +1,24 @@ +# Copyright (c) 2011, Chris Umbel + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +SHELL := /bin/bash + +test: + jasmine-node spec/ diff --git a/node_modules/thirty-two/README.md b/node_modules/thirty-two/README.md new file mode 100644 index 0000000..fd81e38 --- /dev/null +++ b/node_modules/thirty-two/README.md @@ -0,0 +1,15 @@ +# thirty-two + +Implementation of RFC 3548 Base32 encoding/decoding for node. + +## Installation + + npm install thirty-two + +## Usage + + var base32 = require('thirty-two'); + base32.encode('node'); + // output: NZXWIZI= + base32.decode('NZXWIZI='); + //output: node diff --git a/node_modules/thirty-two/index.js b/node_modules/thirty-two/index.js new file mode 100644 index 0000000..28d6a19 --- /dev/null +++ b/node_modules/thirty-two/index.js @@ -0,0 +1,23 @@ +/* +Copyright (c) 2011, Chris Umbel + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +module.exports = require('./lib/base32/'); diff --git a/node_modules/thirty-two/lib/thirty-two/index.js b/node_modules/thirty-two/lib/thirty-two/index.js new file mode 100644 index 0000000..8cb3e2f --- /dev/null +++ b/node_modules/thirty-two/lib/thirty-two/index.js @@ -0,0 +1,26 @@ +/* +Copyright (c) 2011, Chris Umbel + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +var base32 = require('./thirty-two'); + +exports.encode = base32.encode; +exports.decode = base32.decode; diff --git a/node_modules/thirty-two/lib/thirty-two/thirty-two.js b/node_modules/thirty-two/lib/thirty-two/thirty-two.js new file mode 100644 index 0000000..f884377 --- /dev/null +++ b/node_modules/thirty-two/lib/thirty-two/thirty-two.js @@ -0,0 +1,128 @@ +/* +Copyright (c) 2011, Chris Umbel + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ +'use strict'; + +var charTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; +var byteTable = [ + 0xff, 0xff, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, + 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, + 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, + 0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, + 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, + 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, + 0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff +]; + +function quintetCount(buff) { + var quintets = Math.floor(buff.length / 5); + return buff.length % 5 === 0 ? quintets: quintets + 1; +} + +exports.encode = function(plain) { + if(!Buffer.isBuffer(plain)){ + plain = new Buffer(plain); + } + var i = 0; + var j = 0; + var shiftIndex = 0; + var digit = 0; + var encoded = new Buffer(quintetCount(plain) * 8); + + /* byte by byte isn't as pretty as quintet by quintet but tests a bit + faster. will have to revisit. */ + while(i < plain.length) { + var current = plain[i]; + + if(shiftIndex > 3) { + digit = current & (0xff >> shiftIndex); + shiftIndex = (shiftIndex + 5) % 8; + digit = (digit << shiftIndex) | ((i + 1 < plain.length) ? + plain[i + 1] : 0) >> (8 - shiftIndex); + i++; + } else { + digit = (current >> (8 - (shiftIndex + 5))) & 0x1f; + shiftIndex = (shiftIndex + 5) % 8; + if(shiftIndex === 0) i++; + } + + encoded[j] = charTable.charCodeAt(digit); + j++; + } + + for(i = j; i < encoded.length; i++) { + encoded[i] = 0x3d; //'='.charCodeAt(0) + } + + return encoded; +}; + +exports.decode = function(encoded) { + var shiftIndex = 0; + var plainDigit = 0; + var plainChar; + var plainPos = 0; + if(!Buffer.isBuffer(encoded)){ + encoded = new Buffer(encoded); + } + var decoded = new Buffer(Math.ceil(encoded.length * 5 / 8)); + + /* byte by byte isn't as pretty as octet by octet but tests a bit + faster. will have to revisit. */ + for(var i = 0; i < encoded.length; i++) { + if(encoded[i] === 0x3d){ //'=' + break; + } + + var encodedByte = encoded[i] - 0x30; + + if(encodedByte < byteTable.length) { + plainDigit = byteTable[encodedByte]; + + if(shiftIndex <= 3) { + shiftIndex = (shiftIndex + 5) % 8; + + if(shiftIndex === 0) { + plainChar |= plainDigit; + decoded[plainPos] = plainChar; + plainPos++; + plainChar = 0; + } else { + plainChar |= 0xff & (plainDigit << (8 - shiftIndex)); + } + } else { + shiftIndex = (shiftIndex + 5) % 8; + plainChar |= 0xff & (plainDigit >>> shiftIndex); + decoded[plainPos] = plainChar; + plainPos++; + + plainChar = 0xff & (plainDigit << (8 - shiftIndex)); + } + } else { + throw new Error('Invalid input - it is not base32 encoded string'); + } + } + + return decoded.slice(0, plainPos); +}; diff --git a/node_modules/thirty-two/package.json b/node_modules/thirty-two/package.json new file mode 100644 index 0000000..fc341c7 --- /dev/null +++ b/node_modules/thirty-two/package.json @@ -0,0 +1,15 @@ +{ + "name": "thirty-two", + "description": "Implementation RFC 3548 Base32 encoding/decoding for node.", + "version": "1.0.2", + "engines": { + "node": ">=0.2.6" + }, + "author": "Chris Umbel <chris@chrisumbel.com>", + "keywords": ["base32", "encoding"], + "main": "./lib/thirty-two/index.js", + "repository": { + "type": "git", + "url": "git://github.com/chrisumbel/thirty-two.git" + } +} diff --git a/node_modules/thirty-two/spec/thirty-two_spec.js b/node_modules/thirty-two/spec/thirty-two_spec.js new file mode 100644 index 0000000..a0e0c0a --- /dev/null +++ b/node_modules/thirty-two/spec/thirty-two_spec.js @@ -0,0 +1,63 @@ +/* +Copyright (c) 2011, Chris Umbel + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ +if(!expect){ + function expect(a){ + return { + toBe: function(b){ + require('assert').strictEqual(a, b); + } + }; + } +} +var base32 = require('../lib/thirty-two/'); + +describe('thirty-two', function() { + it('should encode', function() { + expect(base32.encode('a').toString()).toBe('ME======'); + expect(base32.encode('be').toString()).toBe('MJSQ===='); + expect(base32.encode('bee').toString()).toBe('MJSWK==='); + expect(base32.encode('beer').toString()).toBe('MJSWK4Q='); + expect(base32.encode('beers').toString()).toBe('MJSWK4TT'); + expect(base32.encode('beers 1').toString()).toBe('MJSWK4TTEAYQ===='); + expect(base32.encode('shockingly dismissed').toString()).toBe('ONUG6Y3LNFXGO3DZEBSGS43NNFZXGZLE'); + }); + + + it('should decode', function() { + expect(base32.decode('ME======').toString()).toBe('a'); + expect(base32.decode('MJSQ====').toString()).toBe('be'); + expect(base32.decode('ONXW4===').toString()).toBe('son'); + expect(base32.decode('MJSWK===').toString()).toBe('bee'); + expect(base32.decode('MJSWK4Q=').toString()).toBe('beer'); + expect(base32.decode('MJSWK4TT').toString()).toBe('beers'); + expect(base32.decode('mjswK4TT').toString()).toBe('beers'); + expect(base32.decode('MJSWK4TTN5XA====').toString()).toBe('beerson'); + expect(base32.decode('MJSWK4TTEAYQ====').toString()).toBe('beers 1'); + expect(base32.decode('ONUG6Y3LNFXGO3DZEBSGS43NNFZXGZLE').toString()).toBe('shockingly dismissed'); + }); + + it('should be binary safe', function() { + expect(base32.decode(base32.encode(new Buffer([0x00, 0xff, 0x88]))).toString('hex')).toBe('00ff88'); + expect(base32.encode(new Buffer("f61e1f998d69151de8334dbe753ab17ae831c13849a6aecd95d0a4e5dc25", 'hex')).toString()).toBe('6YPB7GMNNEKR32BTJW7HKOVRPLUDDQJYJGTK5TMV2CSOLXBF'); + expect(base32.decode('6YPB7GMNNEKR32BTJW7HKOVRPLUDDQJYJGTK5TMV2CSOLXBF').toString('hex')).toBe('f61e1f998d69151de8334dbe753ab17ae831c13849a6aecd95d0a4e5dc25'); + }); +}); |