Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with TypeScript and FileKeyInfo #272

Closed
djaqua opened this issue Jan 14, 2023 · 2 comments · Fixed by #273
Closed

Issue with TypeScript and FileKeyInfo #272

djaqua opened this issue Jan 14, 2023 · 2 comments · Fixed by #273

Comments

@djaqua
Copy link
Contributor

djaqua commented Jan 14, 2023

Even with @types/xml-crypto, I am unable to usefully extend FileKeyInfo. The syntax checks out and TypeScript compiles, but the signature does not honor the methods getKey and getKeyInfo, but proceeds to use the methods as currently defined on FileKeyInfo.

Since TypeScript is strongly typed, I am unable to assign anything to the keyInfoProvider property of the signature object besides instances of KeyInfoProvider and its subclasses.

I have figured out that this happens because both methods are properties of the instance of FileKeyInfo itself, and not its prototype.

The solution is simple, but perhaps you know of a reason not to proceed (for backward's compatibility reasons etc etc). Change:

function FileKeyInfo(file) {
  this.file = file;

  this.getKeyInfo = function (key, prefix) {
    prefix = prefix || "";
    prefix = prefix ? prefix + ":" : prefix;
    return "<" + prefix + "X509Data></" + prefix + "X509Data>";
  };

  this.getKey = function (keyInfo) {
    return fs.readFileSync(this.file);
  };
}

To this:

function FileKeyInfo(file) {
  this.file = file;
}

FileKeyInfo.prototype.getKeyInfo = function (key, prefix) {
  prefix = prefix || "";
  prefix = prefix ? prefix + ":" : prefix;
  return "<" + prefix + "X509Data></" + prefix + "X509Data>";
};

FileKeyInfo.prototype.getKey = function (keyInfo) {
  return fs.readFileSync(this.file);
}

I tested this locally and it passed all your existing unit tests and it also solved my issue. I would be happy to create a PR and submit for review :)

@cjbarth
Copy link
Contributor

cjbarth commented Jan 16, 2023

Please submit the PR for review. The currently active maintainers on this project don't have a clear view of the history of this and related code, even the arguments seem inconsistently used. Your help to clean this up would be most welcome. As long as tests pass, that is a win in my book. If something breaks, then we need more tests.

@djaqua
Copy link
Contributor Author

djaqua commented Jan 17, 2023

Here's the PR: #273

As I explained to @LoneRifle , I am definitely interested in helping out with this. My ability to really get anything done is going to be limited to Sunday afternoons, but glad you help sort out where we can move this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants