diff --git a/.cirrus.yml b/.cirrus.yml index 7a10c26..2a531e5 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -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: "" diff --git a/p11mod/p11mod.go b/p11mod/p11mod.go index 541d816..ca9f79e 100644 --- a/p11mod/p11mod.go +++ b/p11mod/p11mod.go @@ -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 } diff --git a/types.go b/types.go index 1167dad..5b41ddc 100644 --- a/types.go +++ b/types.go @@ -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 } @@ -142,9 +142,10 @@ 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 @@ -152,7 +153,7 @@ func fromTemplate(template []*pkcs11.Attribute, clist C.CK_ATTRIBUTE_PTR) error copy(goBuf[:], x.Value) c.ulValueLen = cLen - } else { + default: c.ulValueLen = C.CK_UNAVAILABLE_INFORMATION bufferTooSmall = true }