-
Notifications
You must be signed in to change notification settings - Fork 24
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
Add NewCertificateFromX509
function
#239
Conversation
The new function can create a `x509util.Certificate` from an x509.Certificate (used as a template). It also supports options, to provide a template, so that data can be set in the certificate. Currently a template is always required. An error will be returned when no template is provided.
I ❤️ the option of using generics. |
@maraino I've gone ahead and updated the usages within Do you think it's useful to provide helper functions like these: func WithCSRTemplate(text string, data TemplateData) Option[*x509.CertificateRequest] {
return WithTemplate[*x509.CertificateRequest](text, data)
}
// or:
func WithCertificateRequestTemplate(text string, data TemplateData) Option[*x509.CertificateRequest] {
return WithTemplate[*x509.CertificateRequest](text, data)
} Usage would then look a bit cleaner: fn := WithCSRTemplate(tt.args.text, tt.args.data) Instead of fn := WithTemplate[*x509.CertificateRequest](tt.args.text, tt.args.data) Defining aliases like the below is possible, but then requires defining the type CertificateOptions Options[*x509.Certificate]
func (co *CertificateOptions) apply(t *x509.Certificate, opts []Option[*x509.Certificate]) (*Options[*x509.Certificate], error) {
o := &Options[*x509.Certificate]{}
return o.apply(t, opts)
} Then another thing we could add is a type alias for a single type CertificateOption Option[*x509.Certificate]
func (co *CertificateOptions) apply(t *x509.Certificate, opts []CertificateOption) (*Options[*x509.Certificate], error) {
o := &Options[*x509.Certificate]{}
var copts []Option[*x509.Certificate]
for _, opt := range opts {
copts = append(copts, Option[*x509.Certificate](opt))
}
return o.apply(t, copts)
}
// resulting in this function signature:
func NewCertificateFromX509(template *x509.Certificate, opts ...CertificateOption) (*Certificate, error) Let me know if you think the above things would be useful, and which you would like to have available. |
Closing in favor of #248. |
The new function can create a
x509util.Certificate
from an x509.Certificate (used as a template). It also supports options, to provide a template, so that data can be set in the certificate.Currently a template is always required. An error will be returned when no template is provided.
@maraino: I'll add tests later if this approach seems sensible to you. I don't think we can use generics to handle both
x509.Certificate
andx509.CertificateRequest
options using only a single implementation, so I copied them over.