1'use strict'; 2 3const { 4 certExportChallenge, 5 certExportPublicKey, 6 certVerifySpkac, 7} = internalBinding('crypto'); 8 9const { 10 getArrayBufferOrView, 11} = require('internal/crypto/util'); 12 13// The functions contained in this file cover the SPKAC format 14// (also referred to as Netscape SPKI). A general description of 15// the format can be found at https://en.wikipedia.org/wiki/SPKAC 16 17function verifySpkac(spkac, encoding) { 18 return certVerifySpkac( 19 getArrayBufferOrView(spkac, 'spkac', encoding)); 20} 21 22function exportPublicKey(spkac, encoding) { 23 return certExportPublicKey( 24 getArrayBufferOrView(spkac, 'spkac', encoding)); 25} 26 27function exportChallenge(spkac, encoding) { 28 return certExportChallenge( 29 getArrayBufferOrView(spkac, 'spkac', encoding)); 30} 31 32// The legacy implementation of this exposed the Certificate 33// object and required that users create an instance before 34// calling the member methods. This API pattern has been 35// deprecated, however, as the method implementations do not 36// rely on any object state. 37 38// For backwards compatibility reasons, this cannot be converted into a 39// ES6 Class. 40function Certificate() { 41 if (!(this instanceof Certificate)) 42 return new Certificate(); 43} 44 45Certificate.prototype.verifySpkac = verifySpkac; 46Certificate.prototype.exportPublicKey = exportPublicKey; 47Certificate.prototype.exportChallenge = exportChallenge; 48 49Certificate.exportChallenge = exportChallenge; 50Certificate.exportPublicKey = exportPublicKey; 51Certificate.verifySpkac = verifySpkac; 52 53module.exports = Certificate; 54