Skip to content

Commit

Permalink
Rename variables and use helper function for root CA check
Browse files Browse the repository at this point in the history
Updated `FormatDid` function to use a more descriptive variable `caCert` instead of `ca`. Modified the `FindRootCertificate` function to use the `x509_cert.IsRootCa` helper function for improved readability and consistency in the root CA check.
  • Loading branch information
rolandgroen committed Oct 14, 2024
1 parent 976057c commit 24ad916
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions did_x509/did_x509.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ type X509Did struct {

// FormatDid constructs a decentralized identifier (DID) from a certificate chain and an optional policy.
// It returns the formatted DID string or an error if the root certificate or hash calculation fails.
func FormatDid(ca *x509.Certificate, policy string) (string, error) {
func FormatDid(caCert *x509.Certificate, policy string) (string, error) {
alg := "sha512"
rootHash, err := x509_cert.Hash(ca.Raw, alg)
rootHash, err := x509_cert.Hash(caCert.Raw, alg)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -77,7 +77,7 @@ func CreatePolicy(otherNameValue string, sanType x509_cert.SanTypeName) string {
// FindRootCertificate traverses a chain of x509 certificates and returns the first certificate that is a CA.
func FindRootCertificate(chain []*x509.Certificate) (*x509.Certificate, error) {
for _, cert := range chain {
if cert.IsCA {
if x509_cert.IsRootCa(cert) {
return cert, nil
}
}
Expand Down

0 comments on commit 24ad916

Please sign in to comment.