This commit is contained in:
Kagami Hiiragi 2015-01-16 01:43:15 +03:00
parent 51974d4666
commit 52dce062c4
3 changed files with 14 additions and 14 deletions

View File

@ -50,9 +50,9 @@ exports.getPrivate = function() {
}; };
/** /**
* Generate public key for a given private key. * Generate public key for the given private key.
* @param {Buffer} privateKey - Private key * @param {Buffer} privateKey - A 32-byte private key
* @return {Buffer} Public key. * @return {Buffer} A 65-byte (uncompressed) public key.
* @function * @function
*/ */
exports.getPublic = eccrypto.getPublic; exports.getPublic = eccrypto.getPublic;

View File

@ -27,18 +27,18 @@ exports.version = {
* payload * payload
* @return {Object} Decoded `version` structure. * @return {Object} Decoded `version` structure.
*/ */
decode: function(payload) { decode: function(buf) {
// 4 + 8 + 8 + 26 + 26 + 8 + (1+) + (1+) // 4 + 8 + 8 + 26 + 26 + 8 + (1+) + (1+)
assert(payload.length >= 82, "Message payload is too small"); assert(buf.length >= 82, "Buffer is too small");
var protoVersion = payload.readUInt32BE(0, true); var protoVersion = buf.readUInt32BE(0, true);
var services = structs.serviceFeatures.decode(payload.slice(4, 12)); var services = structs.serviceFeatures.decode(buf.slice(4, 12));
var time = util.readTime64BE(payload, 12); var time = util.readTime64BE(buf, 12);
var short = {short: true}; var short = {short: true};
var addrRecv = structs.net_addr.decode(payload.slice(20, 46), short); var addrRecv = structs.net_addr.decode(buf.slice(20, 46), short);
var addrFrom = structs.net_addr.decode(payload.slice(46, 72), short); var addrFrom = structs.net_addr.decode(buf.slice(46, 72), short);
var nonce = new Buffer(8); var nonce = new Buffer(8);
payload.copy(nonce, 0, 72, 80); buf.copy(nonce, 0, 72, 80);
var decodedUa = UserAgent.decode(payload.slice(80)); var decodedUa = UserAgent.decode(buf.slice(80));
var decodedStreamNumbers = structs.var_int_list.decode(decodedUa.rest); var decodedStreamNumbers = structs.var_int_list.decode(decodedUa.rest);
return { return {
version: protoVersion, version: protoVersion,

View File

@ -205,7 +205,7 @@ exports.var_str = {
var length = decoded.length + strLength; var length = decoded.length + strLength;
assert(buf.length >= length, "Buffer is too small"); assert(buf.length >= length, "Buffer is too small");
// XXX(Kagami): Spec doesn't mention encoding, using UTF-8. // XXX(Kagami): Spec doesn't mention encoding, using UTF-8.
var str = decoded.rest.slice(0, strLength).toString(); var str = decoded.rest.slice(0, strLength).toString("utf8");
var rest = decoded.rest.slice(strLength); var rest = decoded.rest.slice(strLength);
return {str: str, length: length, rest: rest}; return {str: str, length: length, rest: rest};
}, },
@ -217,7 +217,7 @@ exports.var_str = {
*/ */
encode: function(str) { encode: function(str) {
// XXX(Kagami): Spec doesn't mention encoding, using UTF-8. // XXX(Kagami): Spec doesn't mention encoding, using UTF-8.
var strBuf = new Buffer(str); var strBuf = new Buffer(str, "utf8");
return Buffer.concat([var_int.encode(strBuf.length), strBuf]); return Buffer.concat([var_int.encode(strBuf.length), strBuf]);
}, },
}; };