]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/request/node_modules/http-signature/node_modules/sshpk/lib/ed-compat.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / request / node_modules / http-signature / node_modules / sshpk / lib / ed-compat.js
diff --git a/org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/request/node_modules/http-signature/node_modules/sshpk/lib/ed-compat.js b/org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/request/node_modules/http-signature/node_modules/sshpk/lib/ed-compat.js
new file mode 100644 (file)
index 0000000..5365fb1
--- /dev/null
@@ -0,0 +1,96 @@
+// Copyright 2015 Joyent, Inc.
+
+module.exports = {
+       Verifier: Verifier,
+       Signer: Signer
+};
+
+var nacl;
+var stream = require('stream');
+var util = require('util');
+var assert = require('assert-plus');
+var Signature = require('./signature');
+
+function Verifier(key, hashAlgo) {
+       if (nacl === undefined)
+               nacl = require('tweetnacl');
+
+       if (hashAlgo.toLowerCase() !== 'sha512')
+               throw (new Error('ED25519 only supports the use of ' +
+                   'SHA-512 hashes'));
+
+       this.key = key;
+       this.chunks = [];
+
+       stream.Writable.call(this, {});
+}
+util.inherits(Verifier, stream.Writable);
+
+Verifier.prototype._write = function (chunk, enc, cb) {
+       this.chunks.push(chunk);
+       cb();
+};
+
+Verifier.prototype.update = function (chunk) {
+       if (typeof (chunk) === 'string')
+               chunk = new Buffer(chunk, 'binary');
+       this.chunks.push(chunk);
+};
+
+Verifier.prototype.verify = function (signature, fmt) {
+       var sig;
+       if (Signature.isSignature(signature, [2, 0])) {
+               if (signature.type !== 'ed25519')
+                       return (false);
+               sig = signature.toBuffer('raw');
+
+       } else if (typeof (signature) === 'string') {
+               sig = new Buffer(signature, 'base64');
+
+       } else if (Signature.isSignature(signature, [1, 0])) {
+               throw (new Error('signature was created by too old ' +
+                   'a version of sshpk and cannot be verified'));
+       }
+
+       assert.buffer(sig);
+       return (nacl.sign.detached.verify(
+           new Uint8Array(Buffer.concat(this.chunks)),
+           new Uint8Array(sig),
+           new Uint8Array(this.key.part.R.data)));
+};
+
+function Signer(key, hashAlgo) {
+       if (nacl === undefined)
+               nacl = require('tweetnacl');
+
+       if (hashAlgo.toLowerCase() !== 'sha512')
+               throw (new Error('ED25519 only supports the use of ' +
+                   'SHA-512 hashes'));
+
+       this.key = key;
+       this.chunks = [];
+
+       stream.Writable.call(this, {});
+}
+util.inherits(Signer, stream.Writable);
+
+Signer.prototype._write = function (chunk, enc, cb) {
+       this.chunks.push(chunk);
+       cb();
+};
+
+Signer.prototype.update = function (chunk) {
+       if (typeof (chunk) === 'string')
+               chunk = new Buffer(chunk, 'binary');
+       this.chunks.push(chunk);
+};
+
+Signer.prototype.sign = function () {
+       var sig = nacl.sign.detached(
+           new Uint8Array(Buffer.concat(this.chunks)),
+           new Uint8Array(this.key.part.r.data));
+       var sigBuf = new Buffer(sig);
+       var sigObj = Signature.parse(sigBuf, 'ed25519', 'raw');
+       sigObj.hashAlgorithm = 'sha512';
+       return (sigObj);
+};