Skip to content

Commit

Permalink
Fix formatting using go fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
stv0g authored and ericchiang committed Oct 8, 2023
1 parent 8c3a0ff commit 66ce787
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 46 deletions.
23 changes: 10 additions & 13 deletions piv/key.go
Expand Up @@ -415,11 +415,11 @@ var retiredKeyManagementSlots = map[uint32]Slot{
// RetiredKeyManagementSlot provides access to "retired" slots. Slots meant for old Key Management
// keys that have been rotated. YubiKeys 4 and later support values between 0x82 and 0x95 (inclusive).
//
// slot, ok := RetiredKeyManagementSlot(0x82)
// if !ok {
// // unrecognized slot
// }
// pub, err := yk.GenerateKey(managementKey, slot, key)
// slot, ok := RetiredKeyManagementSlot(0x82)
// if !ok {
// // unrecognized slot
// }
// pub, err := yk.GenerateKey(managementKey, slot, key)
//
// https://developers.yubico.com/PIV/Introduction/Certificate_slots.html#_slot_82_95_retired_key_management
func RetiredKeyManagementSlot(key uint32) (Slot, bool) {
Expand Down Expand Up @@ -808,7 +808,6 @@ func ykGenerateKey(tx *scTx, slot Slot, o Key) (crypto.PublicKey, error) {
alg, ok := algorithmsMap[o.Algorithm]
if !ok {
return nil, fmt.Errorf("unsupported algorithm")

}
tp, ok := touchPolicyMap[o.TouchPolicy]
if !ok {
Expand Down Expand Up @@ -963,12 +962,11 @@ func pinPolicy(yk *YubiKey, slot Slot) (PINPolicy, error) {
// If the public key hasn't been stored externally, it can be provided by
// fetching the slot's attestation certificate:
//
// cert, err := yk.Attest(slot)
// if err != nil {
// // ...
// }
// priv, err := yk.PrivateKey(slot, cert.PublicKey, auth)
//
// cert, err := yk.Attest(slot)
// if err != nil {
// // ...
// }
// priv, err := yk.PrivateKey(slot, cert.PublicKey, auth)
func (yk *YubiKey) PrivateKey(slot Slot, public crypto.PublicKey, auth KeyAuth) (crypto.PrivateKey, error) {
pp := PINPolicyNever
if _, ok := pinPolicyMap[auth.PINPolicy]; ok {
Expand Down Expand Up @@ -1086,7 +1084,6 @@ func ykImportKey(tx *scTx, tags []byte, slot Slot, o Key) error {
alg, ok := algorithmsMap[o.Algorithm]
if !ok {
return fmt.Errorf("unsupported algorithm")

}
tp, ok := touchPolicyMap[o.TouchPolicy]
if !ok {
Expand Down
1 change: 0 additions & 1 deletion piv/key_test.go
Expand Up @@ -876,7 +876,6 @@ func TestSetRSAPrivateKey(t *testing.T) {
slot Slot
wantErr error
}{

{
name: "rsa 1024",
bits: 1024,
Expand Down
2 changes: 1 addition & 1 deletion piv/pcsc_test.go
Expand Up @@ -93,7 +93,7 @@ func TestTransaction(t *testing.T) {
}

func TestErrors(t *testing.T) {
var tests = []struct {
tests := []struct {
sw1, sw2 byte
isErrNotFound bool
isAuthErr bool
Expand Down
58 changes: 27 additions & 31 deletions piv/piv.go
Expand Up @@ -450,15 +450,13 @@ func ykAuthenticate(tx *scTx, key [24]byte, rand io.Reader) error {
// are triple-des keys, however padding isn't verified. To generate a new key,
// generate 24 random bytes.
//
// var newKey [24]byte
// if _, err := io.ReadFull(rand.Reader, newKey[:]); err != nil {
// // ...
// }
// if err := yk.SetManagementKey(piv.DefaultManagementKey, newKey); err != nil {
// // ...
// }
//
//
// var newKey [24]byte
// if _, err := io.ReadFull(rand.Reader, newKey[:]); err != nil {
// // ...
// }
// if err := yk.SetManagementKey(piv.DefaultManagementKey, newKey); err != nil {
// // ...
// }
func (yk *YubiKey) SetManagementKey(oldKey, newKey [24]byte) error {
if err := ykAuthenticate(yk.tx, oldKey, yk.rand); err != nil {
return fmt.Errorf("authenticating with old key: %w", err)
Expand Down Expand Up @@ -494,17 +492,16 @@ func ykSetManagementKey(tx *scTx, key [24]byte, touch bool) error {
//
// To generate a new PIN, use the crypto/rand package.
//
// // Generate a 6 character PIN.
// newPINInt, err := rand.Int(rand.Reader, bit.NewInt(1_000_000))
// if err != nil {
// // ...
// }
// // Format with leading zeros.
// newPIN := fmt.Sprintf("%06d", newPINInt)
// if err := yk.SetPIN(piv.DefaultPIN, newPIN); err != nil {
// // ...
// }
//
// // Generate a 6 character PIN.
// newPINInt, err := rand.Int(rand.Reader, bit.NewInt(1_000_000))
// if err != nil {
// // ...
// }
// // Format with leading zeros.
// newPIN := fmt.Sprintf("%06d", newPINInt)
// if err := yk.SetPIN(piv.DefaultPIN, newPIN); err != nil {
// // ...
// }
func (yk *YubiKey) SetPIN(oldPIN, newPIN string) error {
return ykChangePIN(yk.tx, oldPIN, newPIN)
}
Expand Down Expand Up @@ -555,17 +552,16 @@ func ykUnblockPIN(tx *scTx, puk, newPIN string) error {
//
// To generate a new PUK, use the crypto/rand package.
//
// // Generate a 8 character PUK.
// newPUKInt, err := rand.Int(rand.Reader, big.NewInt(100_000_000))
// if err != nil {
// // ...
// }
// // Format with leading zeros.
// newPUK := fmt.Sprintf("%08d", newPUKInt)
// if err := yk.SetPUK(piv.DefaultPUK, newPUK); err != nil {
// // ...
// }
//
// // Generate a 8 character PUK.
// newPUKInt, err := rand.Int(rand.Reader, big.NewInt(100_000_000))
// if err != nil {
// // ...
// }
// // Format with leading zeros.
// newPUK := fmt.Sprintf("%08d", newPUKInt)
// if err := yk.SetPUK(piv.DefaultPUK, newPUK); err != nil {
// // ...
// }
func (yk *YubiKey) SetPUK(oldPUK, newPUK string) error {
return ykChangePUK(yk.tx, oldPUK, newPUK)
}
Expand Down

0 comments on commit 66ce787

Please sign in to comment.