Skip to content

Commit

Permalink
Merge #102: Cirrus: Mark gocritic linter as mandatory
Browse files Browse the repository at this point in the history
f6e8748 Cirrus: Mark gocritic linter as mandatory (Jeremy Rand)
f00c922 p11mod / GetMechanismList: Call slot.Mechanisms() (Jeremy Rand)
5401d6b fromTemplate: rewrite if-else chain to switch (Jeremy Rand)
9a709fa toTemplate: space between // and comment text (Jeremy Rand)

Pull request description:

  Refs #97

Top commit has no ACKs.

Tree-SHA512: 7e82e450546fee84c5e2db86a47edc49fcac1a7abb9611175a6f0fc83289f4448a5a5d149327b6453b343a0e1501abcfdce00a9559230a76a7e67d87a8f60736
  • Loading branch information
Jeremy Rand committed Aug 10, 2022
2 parents 0a13745 + f6e8748 commit dc1554d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ task:
GOLANGCI_ARGS: "--new-from-rev=HEAD~"
- name: Go Lint Mandatory
env:
GOLANGCI_ARGS: "--disable=cyclop,dupl,errcheck,errname,errorlint,exhaustive,funlen,gci,gocritic,godox,goerr113,gofmt,gofumpt,goimports,golint,gomnd,gosimple,govet,ifshort,lll,makezero,nestif,nlreturn,nosnakecase,paralleltest,revive,stylecheck,thelper,unconvert,varnamelen,wrapcheck,wsl"
GOLANGCI_ARGS: "--disable=cyclop,dupl,errcheck,errname,errorlint,exhaustive,funlen,gci,godox,goerr113,gofmt,gofumpt,goimports,golint,gomnd,gosimple,govet,ifshort,lll,makezero,nestif,nlreturn,nosnakecase,paralleltest,revive,stylecheck,thelper,unconvert,varnamelen,wrapcheck,wsl"
- name: Go Lint
env:
GOLANGCI_ARGS: ""
Expand Down
10 changes: 7 additions & 3 deletions p11mod/p11mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,18 @@ func (ll *llBackend) GetTokenInfo(slotID uint) (pkcs11.TokenInfo, error) {
}

func (ll *llBackend) GetMechanismList(slotID uint) ([]*pkcs11.Mechanism, error) {
//slot, err := ll.getSlotByID(slotID)
_, err := ll.getSlotByID(slotID)
slot, err := ll.getSlotByID(slotID)
if err != nil {
return []*pkcs11.Mechanism{}, err
}

_, err = slot.Mechanisms()
if err != nil {
return []*pkcs11.Mechanism{}, err
}

// TODO
log.Println("p11mod GetMechanismList: not implemented")
log.Println("p11mod GetMechanismList: not implemented, see https://github.com/miekg/pkcs11/issues/158")
return []*pkcs11.Mechanism{}, nil
}

Expand Down
9 changes: 5 additions & 4 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func toTemplate(clist C.CK_ATTRIBUTE_PTR, size C.CK_ULONG) []*pkcs11.Attribute {
if int(c.ulValueLen) != -1 {
buf := unsafe.Pointer(C.getAttributePval(c))
x.Value = C.GoBytes(buf, C.int(c.ulValueLen))
//C.free(buf) // Removed compared to miekg implementation since it's not desired here
// C.free(buf) // Removed compared to miekg implementation since it's not desired here
}
l2[i] = x
}
Expand All @@ -142,17 +142,18 @@ func fromTemplate(template []*pkcs11.Attribute, clist C.CK_ATTRIBUTE_PTR) error
continue
}
cLen := C.CK_ULONG(uint(len(x.Value)))
if C.getAttributePval(c) == nil {
switch {
case C.getAttributePval(c) == nil:
c.ulValueLen = cLen
} else if c.ulValueLen >= cLen {
case c.ulValueLen >= cLen:
buf := unsafe.Pointer(C.getAttributePval(c))

// Adapted from solution 3 of https://stackoverflow.com/a/35675259
goBuf := (*[1 << 30]byte)(buf)
copy(goBuf[:], x.Value)

c.ulValueLen = cLen
} else {
default:
c.ulValueLen = C.CK_UNAVAILABLE_INFORMATION
bufferTooSmall = true
}
Expand Down

0 comments on commit dc1554d

Please sign in to comment.