-
Notifications
You must be signed in to change notification settings - Fork 3
Support for intermediate certificates #2
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
base: master
Are you sure you want to change the base?
Conversation
pkcs7/sign.go
Outdated
| // Create Signature of message | ||
| // message must be of type io.Reader or []byte | ||
| // Returns signature and any error encountered. | ||
| func Sign(message interface{}, certificate *x509.Certificate, privateKey *rsa.PrivateKey) ([]byte, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think message should be changed to interface{}.
Instead, I'd suggest that Sign continues using io.Reader and the calling application can use bytes.NewReader() if it needs to pass in []bytes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you that interface{} is not the best solution.
Instead of using io.Reader I suggest to introduce an interface Hashable Yannic@77cdc19
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not clear on how this would work. Do you intend to change Sign to accept Hashable instead of io.Reader then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think replacing is an option because it wouldn't be compatible with the current version.
func Sign(reader io.Reader, certificate *x509.Certificate, privateKey *rsa.PrivateKey) ([]byte, error) {}
func SignIntermediate(reader io.Reader, certificate *x509.Certificate, privateKey *rsa.PrivateKey, intermediateCertificates []*x509.Certificate) ([]byte, error) {}
func SignData(hashable Hashable, certificate *x509.Certificate, privateKey *rsa.PrivateKey) ([]byte, error) {}
func SignDataIntermediate(hashable Hashable, certificate *x509.Certificate, privateKey *rsa.PrivateKey, intermediateCertificates []*x509.Certificate) ([]byte, error) {}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. But I'm not sure if I see the advantage of of Hashable over using bytes.NewReader() from the std library? Maybe I just need to see an example of how it would be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right that there is no advantage when using []byte, but someone may have some kind of type struct{} he needs to sign. With Hashable, he has the opportunity to compute a checksum without having to serialize it first.
pkcs7/sign.go
Outdated
| signedData := SignedData{ | ||
| // Copy intermediateCertificates to certificate stack | ||
| raw := certificate.Raw | ||
| if intermediateCertificates != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This nil check is unnecessary:
https://play.golang.org/p/4AJfaL9rNu
For more on nil, check out https://www.youtube.com/watch?v=ynoY2xz-F8s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your explanation, I will remove it.
Add interface Hashable
|
Ping? |
No description provided.