Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

crypto: default output encoding to buffer

  • Loading branch information...
commit d917226561774d63b3221186e6f410adc83b54b2 1 parent c11c19b
@indutny authored
View
40 doc/api/crypto.markdown
@@ -87,14 +87,14 @@ Returned by `crypto.createHash`.
Updates the hash content with the given `data`, the encoding of which is given
in `input_encoding` and can be `'buffer'`, `'utf8'`, `'ascii'` or `'binary'`.
-Defaults to `'binary'`.
+Defaults to `'buffer'`.
This can be called many times with new data as it is streamed.
### hash.digest([encoding])
Calculates the digest of all of the passed data to be hashed.
The `encoding` can be `'buffer'`, `'hex'`, `'binary'` or `'base64'`.
-Defaults to `'binary'`.
+Defaults to `'buffer'`.
Note: `hash` object can not be used after `digest()` method been called.
@@ -121,7 +121,7 @@ This can be called many times with new data as it is streamed.
Calculates the digest of all of the passed data to the hmac.
The `encoding` can be `'buffer'`, `'hex'`, `'binary'` or `'base64'`.
-Defaults to `'binary'`.
+Defaults to `'buffer'`.
Note: `hmac` object can not be used after `digest()` method been called.
@@ -157,17 +157,17 @@ Returned by `crypto.createCipher` and `crypto.createCipheriv`.
Updates the cipher with `data`, the encoding of which is given in
`input_encoding` and can be `'buffer'`, `'utf8'`, `'ascii'` or `'binary'`.
-Defaults to `'binary'`.
+Defaults to `'buffer'`.
The `output_encoding` specifies the output format of the enciphered data,
-and can be `'buffer'`, `'binary'`, `'base64'` or `'hex'`. Defaults to `'binary'`.
+and can be `'buffer'`, `'binary'`, `'base64'` or `'hex'`. Defaults to `'buffer'`.
Returns the enciphered contents, and can be called many times with new data as it is streamed.
### cipher.final([output_encoding])
Returns any remaining enciphered contents, with `output_encoding` being one of:
-`'buffer'`, `'binary'`, `'base64'` or `'hex'`. Defaults to `'binary'`.
+`'buffer'`, `'binary'`, `'base64'` or `'hex'`. Defaults to `'buffer'`.
Note: `cipher` object can not be used after `final()` method been called.
@@ -197,18 +197,18 @@ Returned by `crypto.createDecipher` and `crypto.createDecipheriv`.
### decipher.update(data, [input_encoding], [output_encoding])
Updates the decipher with `data`, which is encoded in `'buffer'`, `'binary'`,
-`'base64'` or `'hex'`. Defaults to `'binary'`.
+`'base64'` or `'hex'`. Defaults to `'buffer'`.
The `output_decoding` specifies in what format to return the deciphered
plaintext: `'buffer'`, `'binary'`, `'ascii'` or `'utf8'`.
-Defaults to `'binary'`.
+Defaults to `'buffer'`.
### decipher.final([output_encoding])
Returns any remaining plaintext which is deciphered,
with `output_encoding` being one of: `'buffer'`, `'binary'`, `'ascii'` or
`'utf8'`.
-Defaults to `'binary'`.
+Defaults to `'buffer'`.
Note: `decipher` object can not be used after `final()` method been called.
@@ -241,7 +241,7 @@ Calculates the signature on all the updated data passed through the signer.
`private_key` is a string containing the PEM encoded private key for signing.
Returns the signature in `output_format` which can be `'buffer'`, `'binary'`,
-`'hex'` or `'base64'`. Defaults to `'binary'`.
+`'hex'` or `'base64'`. Defaults to `'buffer'`.
Note: `signer` object can not be used after `sign()` method been called.
@@ -267,7 +267,7 @@ Verifies the signed data by using the `object` and `signature`. `object` is a
string containing a PEM encoded object, which can be one of RSA public key,
DSA public key, or X.509 certificate. `signature` is the previously calculated
signature for the data, in the `signature_format` which can be `'buffer'`,
-`'binary'`, `'hex'` or `'base64'`. Defaults to `'binary'`.
+`'binary'`, `'hex'` or `'base64'`. Defaults to `'buffer'`.
Returns true or false depending on the validity of the signature for the data and public key.
@@ -283,7 +283,7 @@ given bit length. The generator used is `2`.
Creates a Diffie-Hellman key exchange object using the supplied prime. The
generator used is `2`. Encoding can be `'buffer'`, `'binary'`, `'hex'`, or
`'base64'`.
-Defaults to `'binary'`.
+Defaults to `'buffer'`.
## Class: DiffieHellman
@@ -296,7 +296,7 @@ Returned by `crypto.createDiffieHellman`.
Generates private and public Diffie-Hellman key values, and returns the
public key in the specified encoding. This key should be transferred to the
other party. Encoding can be `'binary'`, `'hex'`, or `'base64'`.
-Defaults to `'binary'`.
+Defaults to `'buffer'`.
### diffieHellman.computeSecret(other_public_key, [input_encoding], [output_encoding])
@@ -304,38 +304,38 @@ Computes the shared secret using `other_public_key` as the other party's
public key and returns the computed shared secret. Supplied key is
interpreted using specified `input_encoding`, and secret is encoded using
specified `output_encoding`. Encodings can be `'buffer'`, `'binary'`, `'hex'`,
-or `'base64'`. The input encoding defaults to `'binary'`.
+or `'base64'`. The input encoding defaults to `'buffer'`.
If no output encoding is given, the input encoding is used as output encoding.
### diffieHellman.getPrime([encoding])
Returns the Diffie-Hellman prime in the specified encoding, which can be
-`'buffer'`, `'binary'`, `'hex'`, or `'base64'`. Defaults to `'binary'`.
+`'buffer'`, `'binary'`, `'hex'`, or `'base64'`. Defaults to `'buffer'`.
### diffieHellman.getGenerator([encoding])
Returns the Diffie-Hellman prime in the specified encoding, which can be
-`'buffer'`, `'binary'`, `'hex'`, or `'base64'`. Defaults to `'binary'`.
+`'buffer'`, `'binary'`, `'hex'`, or `'base64'`. Defaults to `'buffer'`.
### diffieHellman.getPublicKey([encoding])
Returns the Diffie-Hellman public key in the specified encoding, which can
-be `'binary'`, `'hex'`, or `'base64'`. Defaults to `'binary'`.
+be `'binary'`, `'hex'`, or `'base64'`. Defaults to `'buffer'`.
### diffieHellman.getPrivateKey([encoding])
Returns the Diffie-Hellman private key in the specified encoding, which can
-be `'buffer'`, `'binary'`, `'hex'`, or `'base64'`. Defaults to `'binary'`.
+be `'buffer'`, `'binary'`, `'hex'`, or `'base64'`. Defaults to `'buffer'`.
### diffieHellman.setPublicKey(public_key, [encoding])
Sets the Diffie-Hellman public key. Key encoding can be `'buffer', ``'binary'`,
-`'hex'` or `'base64'`. Defaults to `'binary'`.
+`'hex'` or `'base64'`. Defaults to `'buffer'`.
### diffieHellman.setPrivateKey(public_key, [encoding])
Sets the Diffie-Hellman private key. Key encoding can be `'buffer'`, `'binary'`,
-`'hex'` or `'base64'`. Defaults to `'binary'`.
+`'hex'` or `'base64'`. Defaults to `'buffer'`.
## crypto.getDiffieHellman(group_name)
View
34 src/node_crypto.cc
@@ -2382,7 +2382,7 @@ class Cipher : public ObjectWrap {
Local<Value> outString;
char* out_hexdigest;
int out_hex_len;
- enum encoding out_enc = ParseEncoding(args[2], BINARY);
+ enum encoding out_enc = ParseEncoding(args[2], BUFFER);
if (out_enc == HEX) {
// Hex encoding
HexEncode(out, out_len, &out_hexdigest, &out_hex_len);
@@ -2466,7 +2466,7 @@ class Cipher : public ObjectWrap {
}
}
- enum encoding enc = ParseEncoding(args[0], BINARY);
+ enum encoding enc = ParseEncoding(args[0], BUFFER);
if (enc == HEX) {
// Hex encoding
HexEncode(out_value, out_len, &out_hexdigest, &out_hex_len);
@@ -2784,7 +2784,7 @@ class Decipher : public ObjectWrap {
char* ciphertext;
int ciphertext_len;
- enum encoding enc = ParseEncoding(args[1], BINARY);
+ enum encoding enc = ParseEncoding(args[1], BUFFER);
if (enc == HEX) {
// Hex encoding
// Do we have a previous hex carry over?
@@ -2841,7 +2841,7 @@ class Decipher : public ObjectWrap {
}
Local<Value> outString;
- enum encoding out_enc = ParseEncoding(args[2], BINARY);
+ enum encoding out_enc = ParseEncoding(args[2], BUFFER);
if (out_enc == UTF8) {
// See if we have any overhang from last utf8 partial ending
if (cipher->incomplete_utf8!=NULL) {
@@ -2909,9 +2909,9 @@ class Decipher : public ObjectWrap {
}
if (args.Length() == 0 || !args[0]->IsString()) {
- outString = Encode(out_value, out_len, BINARY);
+ outString = Encode(out_value, out_len, BUFFER);
} else {
- enum encoding enc = ParseEncoding(args[0], BINARY);
+ enum encoding enc = ParseEncoding(args[0], BUFFER);
if (enc == UTF8) {
// See if we have any overhang from last utf8 partial ending
if (cipher->incomplete_utf8!=NULL) {
@@ -3114,7 +3114,7 @@ class Hmac : public ObjectWrap {
md_len = 0;
}
- enum encoding enc = ParseEncoding(args[0], BINARY);
+ enum encoding enc = ParseEncoding(args[0], BUFFER);
if (enc == HEX) {
// Hex encoding
HexEncode(md_value, md_len, &md_hexdigest, &md_hex_len);
@@ -3261,7 +3261,7 @@ class Hash : public ObjectWrap {
Local<Value> outString;
- enum encoding enc = ParseEncoding(args[0], BINARY);
+ enum encoding enc = ParseEncoding(args[0], BUFFER);
if (enc == HEX) {
// Hex encoding
char* md_hexdigest;
@@ -3466,7 +3466,7 @@ class Sign : public ObjectWrap {
delete [] buf;
- enum encoding enc = ParseEncoding(args[1], BINARY);
+ enum encoding enc = ParseEncoding(args[1], BUFFER);
if (enc == HEX) {
// Hex encoding
HexEncode(md_value, md_len, &md_hexdigest, &md_hex_len);
@@ -3717,7 +3717,7 @@ class Verify : public ObjectWrap {
int r=-1;
- enum encoding enc = ParseEncoding(args[2], BINARY);
+ enum encoding enc = ParseEncoding(args[2], BUFFER);
if (enc == HEX) {
// Hex encoding
HexDecode(hbuf, hlen, (char **)&dbuf, &dlen);
@@ -3927,7 +3927,7 @@ class DiffieHellman : public ObjectWrap {
if (args.Length() > 0 && args[0]->IsString()) {
outString = EncodeWithEncoding(args[0], data, dataSize);
} else {
- outString = Encode(data, dataSize, BINARY);
+ outString = Encode(data, dataSize, BUFFER);
}
delete[] data;
@@ -3953,7 +3953,7 @@ class DiffieHellman : public ObjectWrap {
if (args.Length() > 0 && args[0]->IsString()) {
outString = EncodeWithEncoding(args[0], data, dataSize);
} else {
- outString = Encode(data, dataSize, BINARY);
+ outString = Encode(data, dataSize, BUFFER);
}
delete[] data;
@@ -3980,7 +3980,7 @@ class DiffieHellman : public ObjectWrap {
if (args.Length() > 0 && args[0]->IsString()) {
outString = EncodeWithEncoding(args[0], data, dataSize);
} else {
- outString = Encode(data, dataSize, BINARY);
+ outString = Encode(data, dataSize, BUFFER);
}
delete[] data;
@@ -4013,7 +4013,7 @@ class DiffieHellman : public ObjectWrap {
if (args.Length() > 0 && args[0]->IsString()) {
outString = EncodeWithEncoding(args[0], data, dataSize);
} else {
- outString = Encode(data, dataSize, BINARY);
+ outString = Encode(data, dataSize, BUFFER);
}
delete[] data;
@@ -4046,7 +4046,7 @@ class DiffieHellman : public ObjectWrap {
if (args.Length() > 0 && args[0]->IsString()) {
outString = EncodeWithEncoding(args[0], data, dataSize);
} else {
- outString = Encode(data, dataSize, BINARY);
+ outString = Encode(data, dataSize, BUFFER);
}
delete[] data;
@@ -4137,7 +4137,7 @@ class DiffieHellman : public ObjectWrap {
} else if (args.Length() > 1 && args[1]->IsString()) {
outString = EncodeWithEncoding(args[1], data, dataSize);
} else {
- outString = Encode(data, dataSize, BINARY);
+ outString = Encode(data, dataSize, BUFFER);
}
}
@@ -4284,7 +4284,7 @@ class DiffieHellman : public ObjectWrap {
} else if (enc == BASE64) {
unbase64((unsigned char*)*buf, len, &retbuf, &retlen);
- } else if (enc == BINARY) {
+ } else if (enc == BINARY || enc == BUFFER) {
// Binary - do nothing
} else {
fprintf(stderr, "node-crypto : Diffie-Hellman parameter encoding "
View
14 test/simple/test-crypto.js
@@ -368,7 +368,7 @@ for (var i = 0, l = rfc2202_sha1.length; i < l; i++) {
var a0 = crypto.createHash('sha1').update('Test123').digest('hex');
var a1 = crypto.createHash('md5').update('Test123').digest('binary');
var a2 = crypto.createHash('sha256').update('Test123').digest('base64');
-var a3 = crypto.createHash('sha512').update('Test123').digest(); // binary
+var a3 = crypto.createHash('sha512').update('Test123').digest('binary');
var a4 = crypto.createHash('sha1').update('Test123').digest('buffer');
assert.equal(a0, '8308651804facb7b9af8ffc53a33a22d6a1c8ac2', 'Test SHA1');
@@ -421,11 +421,11 @@ assert.strictEqual(verified, true, 'sign and verify (base 64)');
var s2 = crypto.createSign('RSA-SHA256')
.update('Test123')
- .sign(keyPem); // binary
+ .sign(keyPem, 'binary');
var verified = crypto.createVerify('RSA-SHA256')
.update('Test')
.update('123')
- .verify(certPem, s2); // binary
+ .verify(certPem, s2, 'binary');
assert.strictEqual(verified, true, 'sign and verify (binary)');
var s3 = crypto.createSign('RSA-SHA1')
@@ -554,10 +554,10 @@ var privkey1 = dh1.getPrivateKey();
dh3.setPublicKey(key1);
dh3.setPrivateKey(privkey1);
-assert.equal(dh1.getPrime(), dh3.getPrime());
-assert.equal(dh1.getGenerator(), dh3.getGenerator());
-assert.equal(dh1.getPublicKey(), dh3.getPublicKey());
-assert.equal(dh1.getPrivateKey(), dh3.getPrivateKey());
+assert.deepEqual(dh1.getPrime(), dh3.getPrime());
+assert.deepEqual(dh1.getGenerator(), dh3.getGenerator());
+assert.deepEqual(dh1.getPublicKey(), dh3.getPublicKey());
+assert.deepEqual(dh1.getPrivateKey(), dh3.getPrivateKey());
var secret3 = dh3.computeSecret(key2, 'hex', 'base64');
Please sign in to comment.
Something went wrong with that request. Please try again.