-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make FileKeyInfo extensible for compatibility with TypeScript (#273)
* make FileKeyInfo extensible for compatibility with TypeScript * extract FileKeyInfo into new file; add StringKeyInfo * fix comment in StringKeyInfo --------- Co-authored-by: Andrew Jaqua <andrew@trazi.com> Co-authored-by: LoneRifle <LoneRifle@users.noreply.github.com>
- Loading branch information
1 parent
04e1e78
commit 5abf8fc
Showing
4 changed files
with
74 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
var StringKeyInfo = require("./string-key-info") | ||
, fs = require("fs") | ||
|
||
/** | ||
* A key info provider implementation | ||
* | ||
* @param {string} file path to public certificate | ||
*/ | ||
function FileKeyInfo(file) { | ||
var key = fs.readFileSync(file) | ||
StringKeyInfo.apply(this, [key]) | ||
} | ||
|
||
FileKeyInfo.prototype = StringKeyInfo.prototype | ||
FileKeyInfo.prototype.constructor = FileKeyInfo | ||
|
||
module.exports = FileKeyInfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* A basic string based implementation of a FileInfoProvider | ||
* | ||
* @param {string} key the string contents of a public certificate | ||
*/ | ||
function StringKeyInfo(key) { | ||
this.key = key; | ||
} | ||
|
||
/** | ||
* Builds the contents of a KeyInfo element as an XML string. | ||
* | ||
* Currently, this returns exactly one empty X509Data element | ||
* (e.g. "<X509Data></X509Data>"). The resultant X509Data element will be | ||
* prefaced with a namespace alias if a value for the prefix argument | ||
* is provided. In example, if the value of the prefix argument is 'foo', then | ||
* the resultant XML string will be "<foo:X509Data></foo:X509Data>" | ||
* | ||
* @param key (not used) the signing/private key as a string | ||
* @param prefix an optional namespace alias to be used for the generated XML | ||
* @return an XML string representation of the contents of a KeyInfo element | ||
*/ | ||
StringKeyInfo.prototype.getKeyInfo = function (key, prefix) { | ||
prefix = prefix || ""; | ||
prefix = prefix ? prefix + ":" : prefix; | ||
return "<" + prefix + "X509Data></" + prefix + "X509Data>"; | ||
}; | ||
|
||
/** | ||
* Returns the value of the signing certificate based on the contents of the | ||
* specified KeyInfo. | ||
* | ||
* @param keyInfo (not used) an array with exactly one KeyInfo element | ||
* @return the signing certificate as a string | ||
*/ | ||
StringKeyInfo.prototype.getKey = function (keyInfo) { | ||
return this.key; | ||
}; | ||
|
||
module.exports = StringKeyInfo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters