Skip to content

Commit 0f81de3

Browse files
committed
fixup! crypto: add raw key formats support to the KeyObject APIs
1 parent cacbfb1 commit 0f81de3

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

doc/api/crypto.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,19 +313,19 @@ const generated = await promisify(generateKeyPair)('ec', {
313313
namedCurve: 'P-256',
314314
});
315315

316-
// Export the raw EC public key (compressed by default).
316+
// Export the raw EC public key (uncompressed by default).
317317
const rawPublicKey = generated.publicKey.export({ format: 'raw-public' });
318318

319319
// The following is equivalent.
320-
const rawPublicKeyCompressed = generated.publicKey.export({
320+
const rawPublicKeyUncompressed = generated.publicKey.export({
321321
format: 'raw-public',
322-
type: 'compressed',
322+
type: 'uncompressed',
323323
});
324324

325-
// Export uncompressed point format.
326-
const rawPublicKeyUncompressed = generated.publicKey.export({
325+
// Export compressed point format.
326+
const rawPublicKeyCompressed = generated.publicKey.export({
327327
format: 'raw-public',
328-
type: 'uncompressed',
328+
type: 'compressed',
329329
});
330330

331331
// Export the raw EC private key.
@@ -2416,7 +2416,7 @@ For public keys, the following encoding options can be used:
24162416
See [asymmetric key types][] for format support.
24172417
* `type` {string} When `format` is `'pem'` or `'der'`, must be `'pkcs1'`
24182418
(RSA only) or `'spki'`. For EC keys with `'raw-public'` format, may be
2419-
`'compressed'` (default) or `'uncompressed'`. Ignored when `format` is
2419+
`'uncompressed'` (default) or `'compressed'`. Ignored when `format` is
24202420
`'jwk'`.
24212421

24222422
For private keys, the following encoding options can be used:

lib/internal/crypto/keys.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ const {
353353
return this[kHandle].exportJwk({}, false);
354354
case 'raw-public': {
355355
if (this.asymmetricKeyType === 'ec') {
356-
const { type = 'compressed' } = options;
356+
const { type = 'uncompressed' } = options;
357357
validateOneOf(type, 'options.type', ['compressed', 'uncompressed']);
358358
const form = type === 'compressed' ?
359359
POINT_CONVERSION_COMPRESSED : POINT_CONVERSION_UNCOMPRESSED;

test/parallel/test-crypto-key-objects-raw.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ if (hasOpenSSL(3, 5)) {
249249
}
250250
}
251251

252-
// EC: defaults to compressed, can be switched to uncompressed, both can be imported
252+
// EC: defaults to uncompressed, can be switched to compressed, both can be imported
253253
{
254254
const pubKeyObj = crypto.createPublicKey(
255255
fixtures.readKey('ec_p256_public.pem', 'ascii'));
@@ -258,8 +258,8 @@ if (hasOpenSSL(3, 5)) {
258258
const compressed = pubKeyObj.export({ format: 'raw-public', type: 'compressed' });
259259
const uncompressed = pubKeyObj.export({ format: 'raw-public', type: 'uncompressed' });
260260

261-
// Default is compressed
262-
assert.deepStrictEqual(defaultExport, compressed);
261+
// Default is uncompressed
262+
assert.deepStrictEqual(defaultExport, uncompressed);
263263

264264
// Compressed starts with 0x02 or 0x03 and is 33 bytes for P-256
265265
assert.strictEqual(compressed.byteLength, 33);

0 commit comments

Comments
 (0)