hyperledger / hyperledger/fabric-lib-go
Rename "cert" variable to improve code clarity in pemToPrivateKey function
- Dominant language
- Go
- Stars
- 7
- Forks
- 29
- Avg merge
- 4m
- Merged PRs (30d)
- 2
Description
Description:
In the `pemToPrivateKey` function, the variable name "cert" is used to store the result of `derToPrivateKey(block.Bytes)`. This naming is confusing because:
1. The variable doesn't actually contain a certificate.
2. The function is meant to return a private key, not a certificate.
Proposed change:
Rename the "cert" variable to "privateKey" or "key" to accurately reflect its contents.
- https://github.com/hyperledger/fabric-lib-go/blob/25edd1eaf5f5b4209620bcb4f13d2c0941752820/bccsp/sw/keys.go#L261
- https://github.com/hyperledger/fabric-lib-go/blob/25edd1eaf5f5b4209620bcb4f13d2c0941752820/bccsp/sw/keys.go#L453
Current code:
```go
cert, err := derToPrivateKey(block.Bytes)
if err != nil {
return nil, err
}
return cert, err
```
Suggested code:
```go
key, err := derToPrivateKey(block.Bytes)
if err != nil {
return nil, err
}
return key, err
```
Impact:
This change does not affect the functionality of the code. It's purely a readability improvement that will enhance developer experience and reduce potential confusion when maintaining or reviewing this code.
Contributor guide
Assessment
This issue has not been assessed yet.