_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3 values | text stringlengths 52 85.5k | language stringclasses 1 value | meta_information dict |
|---|---|---|---|---|---|
q11500 | Free | train | func (p *GCMParams) Free() {
if p == nil || p.arena == nil {
return
}
p.arena.Free()
p.params = nil
p.arena = nil
} | go | {
"resource": ""
} |
q11501 | NewPSSParams | train | func NewPSSParams(hashAlg, mgf, saltLength uint) []byte {
p := C.CK_RSA_PKCS_PSS_PARAMS{
hashAlg: C.CK_MECHANISM_TYPE(hashAlg),
mgf: C.CK_RSA_PKCS_MGF_TYPE(mgf),
sLen: C.CK_ULONG(saltLength),
}
return C.GoBytes(unsafe.Pointer(&p), C.int(unsafe.Sizeof(p)))
} | go | {
"resource": ""
} |
q11502 | NewOAEPParams | train | func NewOAEPParams(hashAlg, mgf, sourceType uint, sourceData []byte) *OAEPParams {
return &OAEPParams{
HashAlg: hashAlg,
MGF: mgf,
SourceType: sourceType,
SourceData: sourceData,
}
} | go | {
"resource": ""
} |
q11503 | NewECDH1DeriveParams | train | func NewECDH1DeriveParams(kdf uint, sharedData []byte, publicKeyData []byte) *ECDH1DeriveParams {
return &ECDH1DeriveParams{
KDF: kdf,
SharedData: sharedData,
PublicKeyData: publicKeyData,
}
} | go | {
"resource": ""
} |
q11504 | Initialize | train | func (c *Ctx) Initialize() error {
e := C.Initialize(c.ctx)
return toError(e)
} | go | {
"resource": ""
} |
q11505 | Finalize | train | func (c *Ctx) Finalize() error {
if c.ctx == nil {
return toError(CKR_CRYPTOKI_NOT_INITIALIZED)
}
e := C.Finalize(c.ctx)
return toError(e)
} | go | {
"resource": ""
} |
q11506 | GetInfo | train | func (c *Ctx) GetInfo() (Info, error) {
var p C.ckInfo
e := C.GetInfo(c.ctx, &p)
i := Info{
CryptokiVersion: toVersion(p.cryptokiVersion),
ManufacturerID: strings.TrimRight(string(C.GoBytes(unsafe.Pointer(&p.manufacturerID[0]), 32)), " "),
Flags: uint(p.flags),
LibraryDescription: strings.TrimRight(string(C.GoBytes(unsafe.Pointer(&p.libraryDescription[0]), 32)), " "),
LibraryVersion: toVersion(p.libraryVersion),
}
return i, toError(e)
} | go | {
"resource": ""
} |
q11507 | GetSlotList | train | func (c *Ctx) GetSlotList(tokenPresent bool) ([]uint, error) {
var (
slotList C.CK_ULONG_PTR
ulCount C.CK_ULONG
)
e := C.GetSlotList(c.ctx, cBBool(tokenPresent), &slotList, &ulCount)
if toError(e) != nil {
return nil, toError(e)
}
l := toList(slotList, ulCount)
return l, nil
} | go | {
"resource": ""
} |
q11508 | GetSlotInfo | train | func (c *Ctx) GetSlotInfo(slotID uint) (SlotInfo, error) {
var csi C.CK_SLOT_INFO
e := C.GetSlotInfo(c.ctx, C.CK_ULONG(slotID), &csi)
s := SlotInfo{
SlotDescription: strings.TrimRight(string(C.GoBytes(unsafe.Pointer(&csi.slotDescription[0]), 64)), " "),
ManufacturerID: strings.TrimRight(string(C.GoBytes(unsafe.Pointer(&csi.manufacturerID[0]), 32)), " "),
Flags: uint(csi.flags),
HardwareVersion: toVersion(csi.hardwareVersion),
FirmwareVersion: toVersion(csi.firmwareVersion),
}
return s, toError(e)
} | go | {
"resource": ""
} |
q11509 | GetTokenInfo | train | func (c *Ctx) GetTokenInfo(slotID uint) (TokenInfo, error) {
var cti C.CK_TOKEN_INFO
e := C.GetTokenInfo(c.ctx, C.CK_ULONG(slotID), &cti)
s := TokenInfo{
Label: strings.TrimRight(string(C.GoBytes(unsafe.Pointer(&cti.label[0]), 32)), " "),
ManufacturerID: strings.TrimRight(string(C.GoBytes(unsafe.Pointer(&cti.manufacturerID[0]), 32)), " "),
Model: strings.TrimRight(string(C.GoBytes(unsafe.Pointer(&cti.model[0]), 16)), " "),
SerialNumber: strings.TrimRight(string(C.GoBytes(unsafe.Pointer(&cti.serialNumber[0]), 16)), " "),
Flags: uint(cti.flags),
MaxSessionCount: uint(cti.ulMaxSessionCount),
SessionCount: uint(cti.ulSessionCount),
MaxRwSessionCount: uint(cti.ulMaxRwSessionCount),
RwSessionCount: uint(cti.ulRwSessionCount),
MaxPinLen: uint(cti.ulMaxPinLen),
MinPinLen: uint(cti.ulMinPinLen),
TotalPublicMemory: uint(cti.ulTotalPublicMemory),
FreePublicMemory: uint(cti.ulFreePublicMemory),
TotalPrivateMemory: uint(cti.ulTotalPrivateMemory),
FreePrivateMemory: uint(cti.ulFreePrivateMemory),
HardwareVersion: toVersion(cti.hardwareVersion),
FirmwareVersion: toVersion(cti.firmwareVersion),
UTCTime: strings.TrimRight(string(C.GoBytes(unsafe.Pointer(&cti.utcTime[0]), 16)), " "),
}
return s, toError(e)
} | go | {
"resource": ""
} |
q11510 | GetMechanismList | train | func (c *Ctx) GetMechanismList(slotID uint) ([]*Mechanism, error) {
var (
mech C.CK_ULONG_PTR // in pkcs#11 we're all CK_ULONGs \o/
mechlen C.CK_ULONG
)
e := C.GetMechanismList(c.ctx, C.CK_ULONG(slotID), &mech, &mechlen)
if toError(e) != nil {
return nil, toError(e)
}
// Although the function returns only type, cast them back into real
// attributes as this is used in other functions.
m := make([]*Mechanism, int(mechlen))
for i, typ := range toList(mech, mechlen) {
m[i] = NewMechanism(typ, nil)
}
return m, nil
} | go | {
"resource": ""
} |
q11511 | GetMechanismInfo | train | func (c *Ctx) GetMechanismInfo(slotID uint, m []*Mechanism) (MechanismInfo, error) {
var cm C.CK_MECHANISM_INFO
e := C.GetMechanismInfo(c.ctx, C.CK_ULONG(slotID), C.CK_MECHANISM_TYPE(m[0].Mechanism),
C.CK_MECHANISM_INFO_PTR(&cm))
mi := MechanismInfo{
MinKeySize: uint(cm.ulMinKeySize),
MaxKeySize: uint(cm.ulMaxKeySize),
Flags: uint(cm.flags),
}
return mi, toError(e)
} | go | {
"resource": ""
} |
q11512 | InitToken | train | func (c *Ctx) InitToken(slotID uint, pin string, label string) error {
p := C.CString(pin)
defer C.free(unsafe.Pointer(p))
ll := len(label)
for ll < 32 {
label += " "
ll++
}
l := C.CString(label[:32])
defer C.free(unsafe.Pointer(l))
e := C.InitToken(c.ctx, C.CK_ULONG(slotID), p, C.CK_ULONG(len(pin)), l)
return toError(e)
} | go | {
"resource": ""
} |
q11513 | InitPIN | train | func (c *Ctx) InitPIN(sh SessionHandle, pin string) error {
p := C.CString(pin)
defer C.free(unsafe.Pointer(p))
e := C.InitPIN(c.ctx, C.CK_SESSION_HANDLE(sh), p, C.CK_ULONG(len(pin)))
return toError(e)
} | go | {
"resource": ""
} |
q11514 | SetPIN | train | func (c *Ctx) SetPIN(sh SessionHandle, oldpin string, newpin string) error {
old := C.CString(oldpin)
defer C.free(unsafe.Pointer(old))
new := C.CString(newpin)
defer C.free(unsafe.Pointer(new))
e := C.SetPIN(c.ctx, C.CK_SESSION_HANDLE(sh), old, C.CK_ULONG(len(oldpin)), new, C.CK_ULONG(len(newpin)))
return toError(e)
} | go | {
"resource": ""
} |
q11515 | CloseAllSessions | train | func (c *Ctx) CloseAllSessions(slotID uint) error {
if c.ctx == nil {
return toError(CKR_CRYPTOKI_NOT_INITIALIZED)
}
e := C.CloseAllSessions(c.ctx, C.CK_ULONG(slotID))
return toError(e)
} | go | {
"resource": ""
} |
q11516 | GetSessionInfo | train | func (c *Ctx) GetSessionInfo(sh SessionHandle) (SessionInfo, error) {
var csi C.CK_SESSION_INFO
e := C.GetSessionInfo(c.ctx, C.CK_SESSION_HANDLE(sh), &csi)
s := SessionInfo{SlotID: uint(csi.slotID),
State: uint(csi.state),
Flags: uint(csi.flags),
DeviceError: uint(csi.ulDeviceError),
}
return s, toError(e)
} | go | {
"resource": ""
} |
q11517 | GetOperationState | train | func (c *Ctx) GetOperationState(sh SessionHandle) ([]byte, error) {
var (
state C.CK_BYTE_PTR
statelen C.CK_ULONG
)
e := C.GetOperationState(c.ctx, C.CK_SESSION_HANDLE(sh), &state, &statelen)
defer C.free(unsafe.Pointer(state))
if toError(e) != nil {
return nil, toError(e)
}
b := C.GoBytes(unsafe.Pointer(state), C.int(statelen))
return b, nil
} | go | {
"resource": ""
} |
q11518 | SetOperationState | train | func (c *Ctx) SetOperationState(sh SessionHandle, state []byte, encryptKey, authKey ObjectHandle) error {
e := C.SetOperationState(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_BYTE_PTR(unsafe.Pointer(&state[0])),
C.CK_ULONG(len(state)), C.CK_OBJECT_HANDLE(encryptKey), C.CK_OBJECT_HANDLE(authKey))
return toError(e)
} | go | {
"resource": ""
} |
q11519 | Login | train | func (c *Ctx) Login(sh SessionHandle, userType uint, pin string) error {
p := C.CString(pin)
defer C.free(unsafe.Pointer(p))
e := C.Login(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_USER_TYPE(userType), p, C.CK_ULONG(len(pin)))
return toError(e)
} | go | {
"resource": ""
} |
q11520 | Logout | train | func (c *Ctx) Logout(sh SessionHandle) error {
if c.ctx == nil {
return toError(CKR_CRYPTOKI_NOT_INITIALIZED)
}
e := C.Logout(c.ctx, C.CK_SESSION_HANDLE(sh))
return toError(e)
} | go | {
"resource": ""
} |
q11521 | CreateObject | train | func (c *Ctx) CreateObject(sh SessionHandle, temp []*Attribute) (ObjectHandle, error) {
var obj C.CK_OBJECT_HANDLE
arena, t, tcount := cAttributeList(temp)
defer arena.Free()
e := C.CreateObject(c.ctx, C.CK_SESSION_HANDLE(sh), t, tcount, C.CK_OBJECT_HANDLE_PTR(&obj))
e1 := toError(e)
if e1 == nil {
return ObjectHandle(obj), nil
}
return 0, e1
} | go | {
"resource": ""
} |
q11522 | GetObjectSize | train | func (c *Ctx) GetObjectSize(sh SessionHandle, oh ObjectHandle) (uint, error) {
var size C.CK_ULONG
e := C.GetObjectSize(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_OBJECT_HANDLE(oh), &size)
return uint(size), toError(e)
} | go | {
"resource": ""
} |
q11523 | SetAttributeValue | train | func (c *Ctx) SetAttributeValue(sh SessionHandle, o ObjectHandle, a []*Attribute) error {
arena, pa, palen := cAttributeList(a)
defer arena.Free()
e := C.SetAttributeValue(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_OBJECT_HANDLE(o), pa, palen)
return toError(e)
} | go | {
"resource": ""
} |
q11524 | FindObjects | train | func (c *Ctx) FindObjects(sh SessionHandle, max int) ([]ObjectHandle, bool, error) {
var (
objectList C.CK_OBJECT_HANDLE_PTR
ulCount C.CK_ULONG
)
e := C.FindObjects(c.ctx, C.CK_SESSION_HANDLE(sh), &objectList, C.CK_ULONG(max), &ulCount)
if toError(e) != nil {
return nil, false, toError(e)
}
l := toList(C.CK_ULONG_PTR(unsafe.Pointer(objectList)), ulCount)
// Make again a new list of the correct type.
// This is copying data, but this is not an often used function.
o := make([]ObjectHandle, len(l))
for i, v := range l {
o[i] = ObjectHandle(v)
}
return o, ulCount > C.CK_ULONG(max), nil
} | go | {
"resource": ""
} |
q11525 | Encrypt | train | func (c *Ctx) Encrypt(sh SessionHandle, message []byte) ([]byte, error) {
var (
enc C.CK_BYTE_PTR
enclen C.CK_ULONG
)
e := C.Encrypt(c.ctx, C.CK_SESSION_HANDLE(sh), cMessage(message), C.CK_ULONG(len(message)), &enc, &enclen)
if toError(e) != nil {
return nil, toError(e)
}
s := C.GoBytes(unsafe.Pointer(enc), C.int(enclen))
C.free(unsafe.Pointer(enc))
return s, nil
} | go | {
"resource": ""
} |
q11526 | DecryptFinal | train | func (c *Ctx) DecryptFinal(sh SessionHandle) ([]byte, error) {
var (
plain C.CK_BYTE_PTR
plainlen C.CK_ULONG
)
e := C.DecryptFinal(c.ctx, C.CK_SESSION_HANDLE(sh), &plain, &plainlen)
if toError(e) != nil {
return nil, toError(e)
}
h := C.GoBytes(unsafe.Pointer(plain), C.int(plainlen))
C.free(unsafe.Pointer(plain))
return h, nil
} | go | {
"resource": ""
} |
q11527 | DigestInit | train | func (c *Ctx) DigestInit(sh SessionHandle, m []*Mechanism) error {
arena, mech := cMechanism(m)
defer arena.Free()
e := C.DigestInit(c.ctx, C.CK_SESSION_HANDLE(sh), mech)
return toError(e)
} | go | {
"resource": ""
} |
q11528 | DigestUpdate | train | func (c *Ctx) DigestUpdate(sh SessionHandle, message []byte) error {
e := C.DigestUpdate(c.ctx, C.CK_SESSION_HANDLE(sh), cMessage(message), C.CK_ULONG(len(message)))
if toError(e) != nil {
return toError(e)
}
return nil
} | go | {
"resource": ""
} |
q11529 | DigestKey | train | func (c *Ctx) DigestKey(sh SessionHandle, key ObjectHandle) error {
e := C.DigestKey(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_OBJECT_HANDLE(key))
if toError(e) != nil {
return toError(e)
}
return nil
} | go | {
"resource": ""
} |
q11530 | DigestFinal | train | func (c *Ctx) DigestFinal(sh SessionHandle) ([]byte, error) {
var (
hash C.CK_BYTE_PTR
hashlen C.CK_ULONG
)
e := C.DigestFinal(c.ctx, C.CK_SESSION_HANDLE(sh), &hash, &hashlen)
if toError(e) != nil {
return nil, toError(e)
}
h := C.GoBytes(unsafe.Pointer(hash), C.int(hashlen))
C.free(unsafe.Pointer(hash))
return h, nil
} | go | {
"resource": ""
} |
q11531 | SignRecover | train | func (c *Ctx) SignRecover(sh SessionHandle, data []byte) ([]byte, error) {
var (
sig C.CK_BYTE_PTR
siglen C.CK_ULONG
)
e := C.SignRecover(c.ctx, C.CK_SESSION_HANDLE(sh), cMessage(data), C.CK_ULONG(len(data)), &sig, &siglen)
if toError(e) != nil {
return nil, toError(e)
}
h := C.GoBytes(unsafe.Pointer(sig), C.int(siglen))
C.free(unsafe.Pointer(sig))
return h, nil
} | go | {
"resource": ""
} |
q11532 | VerifyUpdate | train | func (c *Ctx) VerifyUpdate(sh SessionHandle, part []byte) error {
e := C.VerifyUpdate(c.ctx, C.CK_SESSION_HANDLE(sh), cMessage(part), C.CK_ULONG(len(part)))
return toError(e)
} | go | {
"resource": ""
} |
q11533 | VerifyFinal | train | func (c *Ctx) VerifyFinal(sh SessionHandle, signature []byte) error {
e := C.VerifyFinal(c.ctx, C.CK_SESSION_HANDLE(sh), cMessage(signature), C.CK_ULONG(len(signature)))
return toError(e)
} | go | {
"resource": ""
} |
q11534 | VerifyRecover | train | func (c *Ctx) VerifyRecover(sh SessionHandle, signature []byte) ([]byte, error) {
var (
data C.CK_BYTE_PTR
datalen C.CK_ULONG
)
e := C.DecryptVerifyUpdate(c.ctx, C.CK_SESSION_HANDLE(sh), cMessage(signature), C.CK_ULONG(len(signature)), &data, &datalen)
if toError(e) != nil {
return nil, toError(e)
}
h := C.GoBytes(unsafe.Pointer(data), C.int(datalen))
C.free(unsafe.Pointer(data))
return h, nil
} | go | {
"resource": ""
} |
q11535 | DecryptDigestUpdate | train | func (c *Ctx) DecryptDigestUpdate(sh SessionHandle, cipher []byte) ([]byte, error) {
var (
part C.CK_BYTE_PTR
partlen C.CK_ULONG
)
e := C.DecryptDigestUpdate(c.ctx, C.CK_SESSION_HANDLE(sh), cMessage(cipher), C.CK_ULONG(len(cipher)), &part, &partlen)
if toError(e) != nil {
return nil, toError(e)
}
h := C.GoBytes(unsafe.Pointer(part), C.int(partlen))
C.free(unsafe.Pointer(part))
return h, nil
} | go | {
"resource": ""
} |
q11536 | SignEncryptUpdate | train | func (c *Ctx) SignEncryptUpdate(sh SessionHandle, part []byte) ([]byte, error) {
var (
enc C.CK_BYTE_PTR
enclen C.CK_ULONG
)
e := C.SignEncryptUpdate(c.ctx, C.CK_SESSION_HANDLE(sh), cMessage(part), C.CK_ULONG(len(part)), &enc, &enclen)
if toError(e) != nil {
return nil, toError(e)
}
h := C.GoBytes(unsafe.Pointer(enc), C.int(enclen))
C.free(unsafe.Pointer(enc))
return h, nil
} | go | {
"resource": ""
} |
q11537 | DeriveKey | train | func (c *Ctx) DeriveKey(sh SessionHandle, m []*Mechanism, basekey ObjectHandle, a []*Attribute) (ObjectHandle, error) {
var key C.CK_OBJECT_HANDLE
attrarena, ac, aclen := cAttributeList(a)
defer attrarena.Free()
mecharena, mech := cMechanism(m)
defer mecharena.Free()
e := C.DeriveKey(c.ctx, C.CK_SESSION_HANDLE(sh), mech, C.CK_OBJECT_HANDLE(basekey), ac, aclen, &key)
return ObjectHandle(key), toError(e)
} | go | {
"resource": ""
} |
q11538 | SeedRandom | train | func (c *Ctx) SeedRandom(sh SessionHandle, seed []byte) error {
e := C.SeedRandom(c.ctx, C.CK_SESSION_HANDLE(sh), C.CK_BYTE_PTR(unsafe.Pointer(&seed[0])), C.CK_ULONG(len(seed)))
return toError(e)
} | go | {
"resource": ""
} |
q11539 | GenerateRandom | train | func (c *Ctx) GenerateRandom(sh SessionHandle, length int) ([]byte, error) {
var rand C.CK_BYTE_PTR
e := C.GenerateRandom(c.ctx, C.CK_SESSION_HANDLE(sh), &rand, C.CK_ULONG(length))
if toError(e) != nil {
return nil, toError(e)
}
h := C.GoBytes(unsafe.Pointer(rand), C.int(length))
C.free(unsafe.Pointer(rand))
return h, nil
} | go | {
"resource": ""
} |
q11540 | Info | train | func (s Slot) Info() (pkcs11.SlotInfo, error) {
return s.ctx.GetSlotInfo(s.id)
} | go | {
"resource": ""
} |
q11541 | TokenInfo | train | func (s Slot) TokenInfo() (pkcs11.TokenInfo, error) {
return s.ctx.GetTokenInfo(s.id)
} | go | {
"resource": ""
} |
q11542 | Mechanisms | train | func (s Slot) Mechanisms() ([]Mechanism, error) {
list, err := s.ctx.GetMechanismList(s.id)
if err != nil {
return nil, err
}
result := make([]Mechanism, len(list))
for i, mech := range list {
result[i] = Mechanism{
mechanism: mech,
slot: s,
}
}
return result, nil
} | go | {
"resource": ""
} |
q11543 | Info | train | func (m *Mechanism) Info() (pkcs11.MechanismInfo, error) {
return m.slot.ctx.GetMechanismInfo(m.slot.id, []*pkcs11.Mechanism{m.mechanism})
} | go | {
"resource": ""
} |
q11544 | Sign | train | func (priv PrivateKey) Sign(mechanism pkcs11.Mechanism, message []byte) ([]byte, error) {
s := priv.session
s.Lock()
defer s.Unlock()
err := s.ctx.SignInit(s.handle, []*pkcs11.Mechanism{&mechanism}, priv.objectHandle)
if err != nil {
return nil, err
}
out, err := s.ctx.Sign(s.handle, message)
if err != nil {
return nil, err
}
return out, nil
} | go | {
"resource": ""
} |
q11545 | Verify | train | func (pub PublicKey) Verify(mechanism pkcs11.Mechanism, message, signature []byte) error {
s := pub.session
s.Lock()
defer s.Unlock()
err := s.ctx.VerifyInit(s.handle, []*pkcs11.Mechanism{&mechanism}, pub.objectHandle)
if err != nil {
return err
}
err = s.ctx.Verify(s.handle, message, signature)
if err != nil {
return err
}
return nil
} | go | {
"resource": ""
} |
q11546 | Encrypt | train | func (pub PublicKey) Encrypt(mechanism pkcs11.Mechanism, plaintext []byte) ([]byte, error) {
s := pub.session
s.Lock()
defer s.Unlock()
err := s.ctx.EncryptInit(s.handle, []*pkcs11.Mechanism{&mechanism}, pub.objectHandle)
if err != nil {
return nil, err
}
out, err := s.ctx.Encrypt(s.handle, plaintext)
if err != nil {
return nil, err
}
return out, nil
} | go | {
"resource": ""
} |
q11547 | cBBool | train | func cBBool(x bool) C.CK_BBOOL {
if x {
return C.CK_BBOOL(C.CK_TRUE)
}
return C.CK_BBOOL(C.CK_FALSE)
} | go | {
"resource": ""
} |
q11548 | NewAttribute | train | func NewAttribute(typ uint, x interface{}) *Attribute {
// This function nicely transforms *to* an attribute, but there is
// no corresponding function that transform back *from* an attribute,
// which in PKCS#11 is just an byte array.
a := new(Attribute)
a.Type = typ
if x == nil {
return a
}
switch v := x.(type) {
case bool:
if v {
a.Value = []byte{1}
} else {
a.Value = []byte{0}
}
case int:
a.Value = uintToBytes(uint64(v))
case uint:
a.Value = uintToBytes(uint64(v))
case string:
a.Value = []byte(v)
case []byte:
a.Value = v
case time.Time: // for CKA_DATE
a.Value = cDate(v)
default:
panic("pkcs11: unhandled attribute type")
}
return a
} | go | {
"resource": ""
} |
q11549 | cAttributeList | train | func cAttributeList(a []*Attribute) (arena, C.CK_ATTRIBUTE_PTR, C.CK_ULONG) {
var arena arena
if len(a) == 0 {
return nil, nil, 0
}
pa := make([]C.CK_ATTRIBUTE, len(a))
for i, attr := range a {
pa[i]._type = C.CK_ATTRIBUTE_TYPE(attr.Type)
if len(attr.Value) != 0 {
buf, len := arena.Allocate(attr.Value)
// field is unaligned on windows so this has to call into C
C.putAttributePval(&pa[i], buf)
pa[i].ulValueLen = len
}
}
return arena, &pa[0], C.CK_ULONG(len(a))
} | go | {
"resource": ""
} |
q11550 | NewMechanism | train | func NewMechanism(mech uint, x interface{}) *Mechanism {
m := new(Mechanism)
m.Mechanism = mech
if x == nil {
return m
}
switch p := x.(type) {
case *GCMParams, *OAEPParams, *ECDH1DeriveParams:
// contains pointers; defer serialization until cMechanism
m.generator = p
case []byte:
m.Parameter = p
default:
panic("parameter must be one of type: []byte, *GCMParams, *OAEPParams, *ECDH1DeriveParams")
}
return m
} | go | {
"resource": ""
} |
q11551 | Label | train | func (o Object) Label() (string, error) {
labelBytes, err := o.Attribute(pkcs11.CKA_LABEL)
if err != nil {
return "", err
}
return string(labelBytes), nil
} | go | {
"resource": ""
} |
q11552 | Set | train | func (o Object) Set(attributeType uint, value []byte) error {
o.session.Lock()
defer o.session.Unlock()
err := o.session.ctx.SetAttributeValue(o.session.handle, o.objectHandle,
[]*pkcs11.Attribute{pkcs11.NewAttribute(attributeType, value)})
if err != nil {
return err
}
return nil
} | go | {
"resource": ""
} |
q11553 | Copy | train | func (o Object) Copy(template []*pkcs11.Attribute) (Object, error) {
s := o.session
s.Lock()
defer s.Unlock()
newHandle, err := s.ctx.CopyObject(s.handle, o.objectHandle, template)
if err != nil {
return Object{}, err
}
return Object{
session: s,
objectHandle: newHandle,
}, nil
} | go | {
"resource": ""
} |
q11554 | Destroy | train | func (o Object) Destroy() error {
s := o.session
s.Lock()
defer s.Unlock()
return s.ctx.DestroyObject(s.handle, o.objectHandle)
} | go | {
"resource": ""
} |
q11555 | Slots | train | func (m Module) Slots() ([]Slot, error) {
ids, err := m.ctx.GetSlotList(true)
if err != nil {
return nil, err
}
result := make([]Slot, len(ids))
for i, id := range ids {
result[i] = Slot{
ctx: m.ctx,
id: id,
}
}
return result, nil
} | go | {
"resource": ""
} |
q11556 | WriteDirent | train | func WriteDirent(buf []byte, d Dirent) (n int) {
// We want to write bytes with the layout of fuse_dirent
// (http://goo.gl/BmFxob) in host order. The struct must be aligned according
// to FUSE_DIRENT_ALIGN (http://goo.gl/UziWvH), which dictates 8-byte
// alignment.
type fuse_dirent struct {
ino uint64
off uint64
namelen uint32
type_ uint32
name [0]byte
}
const direntAlignment = 8
const direntSize = 8 + 8 + 4 + 4
// Compute the number of bytes of padding we'll need to maintain alignment
// for the next entry.
var padLen int
if len(d.Name)%direntAlignment != 0 {
padLen = direntAlignment - (len(d.Name) % direntAlignment)
}
// Do we have enough room?
totalLen := direntSize + len(d.Name) + padLen
if totalLen > len(buf) {
return
}
// Write the header.
de := fuse_dirent{
ino: uint64(d.Inode),
off: uint64(d.Offset),
namelen: uint32(len(d.Name)),
type_: uint32(d.Type),
}
n += copy(buf[n:], (*[direntSize]byte)(unsafe.Pointer(&de))[:])
// Write the name afterward.
n += copy(buf[n:], d.Name)
// Add any necessary padding.
if padLen != 0 {
var padding [direntAlignment]byte
n += copy(buf[n:], padding[:padLen])
}
return
} | go | {
"resource": ""
} |
q11557 | convertExpirationTime | train | func convertExpirationTime(t time.Time) (secs uint64, nsecs uint32) {
// Fuse represents durations as unsigned 64-bit counts of seconds and 32-bit
// counts of nanoseconds (cf. http://goo.gl/EJupJV). So negative durations
// are right out. There is no need to cap the positive magnitude, because
// 2^64 seconds is well longer than the 2^63 ns range of time.Duration.
d := t.Sub(time.Now())
if d > 0 {
secs = uint64(d / time.Second)
nsecs = uint32((d % time.Second) / time.Nanosecond)
}
return
} | go | {
"resource": ""
} |
q11558 | SetAttributes | train | func (in *inode) SetAttributes(
size *uint64,
mode *os.FileMode,
mtime *time.Time) {
// Update the modification time.
in.attrs.Mtime = time.Now()
// Truncate?
if size != nil {
intSize := int(*size)
// Update contents.
if intSize <= len(in.contents) {
in.contents = in.contents[:intSize]
} else {
padding := make([]byte, intSize-len(in.contents))
in.contents = append(in.contents, padding...)
}
// Update attributes.
in.attrs.Size = *size
}
// Change mode?
if mode != nil {
in.attrs.Mode = *mode
}
// Change mtime?
if mtime != nil {
in.attrs.Mtime = *mtime
}
} | go | {
"resource": ""
} |
q11559 | Init | train | func (c *Connection) Init() (err error) {
// Read the init op.
ctx, op, err := c.ReadOp()
if err != nil {
err = fmt.Errorf("Reading init op: %v", err)
return
}
initOp, ok := op.(*initOp)
if !ok {
c.Reply(ctx, syscall.EPROTO)
err = fmt.Errorf("Expected *initOp, got %T", op)
return
}
// Make sure the protocol version spoken by the kernel is new enough.
min := fusekernel.Protocol{
fusekernel.ProtoVersionMinMajor,
fusekernel.ProtoVersionMinMinor,
}
if initOp.Kernel.LT(min) {
c.Reply(ctx, syscall.EPROTO)
err = fmt.Errorf("Version too old: %v", initOp.Kernel)
return
}
// Downgrade our protocol if necessary.
c.protocol = fusekernel.Protocol{
fusekernel.ProtoVersionMaxMajor,
fusekernel.ProtoVersionMaxMinor,
}
if initOp.Kernel.LT(c.protocol) {
c.protocol = initOp.Kernel
}
// Respond to the init op.
initOp.Library = c.protocol
initOp.MaxReadahead = maxReadahead
initOp.MaxWrite = buffer.MaxWriteSize
initOp.Flags = 0
// Tell the kernel not to use pitifully small 4 KiB writes.
initOp.Flags |= fusekernel.InitBigWrites
// Enable writeback caching if the user hasn't asked us not to.
if !c.cfg.DisableWritebackCaching {
initOp.Flags |= fusekernel.InitWritebackCache
}
c.Reply(ctx, nil)
return
} | go | {
"resource": ""
} |
q11560 | readMessage | train | func (c *Connection) readMessage() (m *buffer.InMessage, err error) {
// Allocate a message.
m = c.getInMessage()
// Loop past transient errors.
for {
// Attempt a reaed.
err = m.Init(c.dev)
// Special cases:
//
// * ENODEV means fuse has hung up.
//
// * EINTR means we should try again. (This seems to happen often on
// OS X, cf. http://golang.org/issue/11180)
//
if pe, ok := err.(*os.PathError); ok {
switch pe.Err {
case syscall.ENODEV:
err = io.EOF
case syscall.EINTR:
err = nil
continue
}
}
if err != nil {
c.putInMessage(m)
m = nil
return
}
return
}
} | go | {
"resource": ""
} |
q11561 | writeMessage | train | func (c *Connection) writeMessage(msg []byte) (err error) {
// Avoid the retry loop in os.File.Write.
n, err := syscall.Write(int(c.dev.Fd()), msg)
if err != nil {
return
}
if n != len(msg) {
err = fmt.Errorf("Wrote %d bytes; expected %d", n, len(msg))
return
}
return
} | go | {
"resource": ""
} |
q11562 | shouldLogError | train | func (c *Connection) shouldLogError(
op interface{},
err error) bool {
// We don't log non-errors.
if err == nil {
return false
}
// We can't log if there's nothing to log to.
if c.errorLogger == nil {
return false
}
switch op.(type) {
case *fuseops.LookUpInodeOp:
// It is totally normal for the kernel to ask to look up an inode by name
// and find the name doesn't exist. For example, this happens when linking
// a new file.
if err == syscall.ENOENT {
return false
}
case *fuseops.GetXattrOp:
if err == syscall.ENODATA || err == syscall.ERANGE {
return false
}
case *unknownOp:
// Don't bother the user with methods we intentionally don't support.
if err == syscall.ENOSYS {
return false
}
}
return true
} | go | {
"resource": ""
} |
q11563 | init | train | func init() {
a := unsafe.Offsetof(OutMessage{}.header) + uintptr(OutMessageHeaderSize)
b := unsafe.Offsetof(OutMessage{}.payload)
if a != b {
log.Panicf(
"header ends at offset %d, but payload starts at offset %d",
a, b)
}
} | go | {
"resource": ""
} |
q11564 | Reset | train | func (m *OutMessage) Reset() {
// Ideally we'd like to write:
//
// m.payloadOffset = 0
// m.header = fusekernel.OutHeader{}
//
// But Go 1.8 beta 2 generates bad code for this
// (https://golang.org/issue/18370). Encourage it to generate the same code
// as Go 1.7.4 did.
if unsafe.Offsetof(m.payload) != 24 {
panic("unexpected OutMessage layout")
}
a := (*[3]uint64)(unsafe.Pointer(m))
a[0] = 0
a[1] = 0
a[2] = 0
} | go | {
"resource": ""
} |
q11565 | Grow | train | func (m *OutMessage) Grow(n int) (p unsafe.Pointer) {
p = m.GrowNoZero(n)
if p != nil {
memclr(p, uintptr(n))
}
return
} | go | {
"resource": ""
} |
q11566 | GrowNoZero | train | func (m *OutMessage) GrowNoZero(n int) (p unsafe.Pointer) {
// Will we overflow the buffer?
o := m.payloadOffset
if len(m.payload)-o < n {
return
}
p = unsafe.Pointer(uintptr(unsafe.Pointer(&m.payload)) + uintptr(o))
m.payloadOffset = o + n
return
} | go | {
"resource": ""
} |
q11567 | AppendString | train | func (m *OutMessage) AppendString(src string) {
p := m.GrowNoZero(len(src))
if p == nil {
panic(fmt.Sprintf("Can't grow %d bytes", len(src)))
}
sh := (*reflect.StringHeader)(unsafe.Pointer(&src))
memmove(p, unsafe.Pointer(sh.Data), uintptr(sh.Len))
return
} | go | {
"resource": ""
} |
q11568 | Bytes | train | func (m *OutMessage) Bytes() []byte {
l := m.Len()
sh := reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(&m.header)),
Len: l,
Cap: l,
}
return *(*[]byte)(unsafe.Pointer(&sh))
} | go | {
"resource": ""
} |
q11569 | Init | train | func (m *InMessage) Init(r io.Reader) (err error) {
n, err := r.Read(m.storage[:])
if err != nil {
return
}
// Make sure the message is long enough.
const headerSize = unsafe.Sizeof(fusekernel.InHeader{})
if uintptr(n) < headerSize {
err = fmt.Errorf("Unexpectedly read only %d bytes.", n)
return
}
m.remaining = m.storage[headerSize:n]
// Check the header's length.
if int(m.Header().Len) != n {
err = fmt.Errorf(
"Header says %d bytes, but we read %d",
m.Header().Len,
n)
return
}
return
} | go | {
"resource": ""
} |
q11570 | Header | train | func (m *InMessage) Header() (h *fusekernel.InHeader) {
h = (*fusekernel.InHeader)(unsafe.Pointer(&m.storage[0]))
return
} | go | {
"resource": ""
} |
q11571 | Consume | train | func (m *InMessage) Consume(n uintptr) (p unsafe.Pointer) {
if m.Len() == 0 || n > m.Len() {
return
}
p = unsafe.Pointer(&m.remaining[0])
m.remaining = m.remaining[n:]
return
} | go | {
"resource": ""
} |
q11572 | ConsumeBytes | train | func (m *InMessage) ConsumeBytes(n uintptr) (b []byte) {
if n > m.Len() {
return
}
b = m.remaining[:n]
m.remaining = m.remaining[n:]
return
} | go | {
"resource": ""
} |
q11573 | opName | train | func opName(op interface{}) string {
// We expect all ops to be pointers.
t := reflect.TypeOf(op).Elem()
// Strip the "Op" from "FooOp".
return strings.TrimSuffix(t.Name(), "Op")
} | go | {
"resource": ""
} |
q11574 | Mount | train | func Mount(
dir string,
server Server,
config *MountConfig) (mfs *MountedFileSystem, err error) {
// Sanity check: make sure the mount point exists and is a directory. This
// saves us from some confusing errors later on OS X.
fi, err := os.Stat(dir)
switch {
case os.IsNotExist(err):
return
case err != nil:
err = fmt.Errorf("Statting mount point: %v", err)
return
case !fi.IsDir():
err = fmt.Errorf("Mount point %s is not a directory", dir)
return
}
// Initialize the struct.
mfs = &MountedFileSystem{
dir: dir,
joinStatusAvailable: make(chan struct{}),
}
// Begin the mounting process, which will continue in the background.
ready := make(chan error, 1)
dev, err := mount(dir, config, ready)
if err != nil {
err = fmt.Errorf("mount: %v", err)
return
}
// Choose a parent context for ops.
cfgCopy := *config
if cfgCopy.OpContext == nil {
cfgCopy.OpContext = context.Background()
}
// Create a Connection object wrapping the device.
connection, err := newConnection(
cfgCopy,
config.DebugLogger,
config.ErrorLogger,
dev)
if err != nil {
err = fmt.Errorf("newConnection: %v", err)
return
}
// Serve the connection in the background. When done, set the join status.
go func() {
server.ServeOps(connection)
mfs.joinStatus = connection.close()
close(mfs.joinStatusAvailable)
}()
// Wait for the mount process to complete.
if err = <-ready; err != nil {
err = fmt.Errorf("mount (background): %v", err)
return
}
return
} | go | {
"resource": ""
} |
q11575 | toMap | train | func (c *MountConfig) toMap() (opts map[string]string) {
isDarwin := runtime.GOOS == "darwin"
opts = make(map[string]string)
// Enable permissions checking in the kernel. See the comments on
// InodeAttributes.Mode.
opts["default_permissions"] = ""
// HACK(jacobsa): Work around what appears to be a bug in systemd v219, as
// shipped in Ubuntu 15.04, where it automatically unmounts any file system
// that doesn't set an explicit name.
//
// When Ubuntu contains systemd v220, this workaround should be removed and
// the systemd bug reopened if the problem persists.
//
// Cf. https://github.com/bazil/fuse/issues/89
// Cf. https://bugs.freedesktop.org/show_bug.cgi?id=90907
fsname := c.FSName
if runtime.GOOS == "linux" && fsname == "" {
fsname = "some_fuse_file_system"
}
// Special file system name?
if fsname != "" {
opts["fsname"] = fsname
}
subtype := c.Subtype
if subtype != "" {
opts["subtype"] = subtype
}
// Read only?
if c.ReadOnly {
opts["ro"] = ""
}
// Handle OS X options.
if isDarwin {
if !c.EnableVnodeCaching {
opts["novncache"] = ""
}
if c.VolumeName != "" {
// Cf. https://github.com/osxfuse/osxfuse/wiki/Mount-options#volname
opts["volname"] = c.VolumeName
}
}
// OS X: disable the use of "Apple Double" (._foo and .DS_Store) files, which
// just add noise to debug output and can have significant cost on
// network-based file systems.
//
// Cf. https://github.com/osxfuse/osxfuse/wiki/Mount-options
if isDarwin {
opts["noappledouble"] = ""
}
// Last but not least: other user-supplied options.
for k, v := range c.Options {
opts[k] = v
}
return
} | go | {
"resource": ""
} |
q11576 | toOptionsString | train | func (c *MountConfig) toOptionsString() string {
var components []string
for k, v := range c.toMap() {
k = escapeOptionsKey(k)
component := k
if v != "" {
component = fmt.Sprintf("%s=%s", k, v)
}
components = append(components, component)
}
return strings.Join(components, ",")
} | go | {
"resource": ""
} |
q11577 | Get | train | func (fl *Freelist) Get() (p unsafe.Pointer) {
l := len(fl.list)
if l == 0 {
return
}
p = fl.list[l-1]
fl.list = fl.list[:l-1]
return
} | go | {
"resource": ""
} |
q11578 | Put | train | func (fl *Freelist) Put(p unsafe.Pointer) {
fl.list = append(fl.list, p)
} | go | {
"resource": ""
} |
q11579 | LT | train | func (a Protocol) LT(b Protocol) bool {
return a.Major < b.Major ||
(a.Major == b.Major && a.Minor < b.Minor)
} | go | {
"resource": ""
} |
q11580 | GE | train | func (a Protocol) GE(b Protocol) bool {
return a.Major > b.Major ||
(a.Major == b.Major && a.Minor >= b.Minor)
} | go | {
"resource": ""
} |
q11581 | SetUp | train | func (t *SubprocessTest) SetUp(ti *ogletest.TestInfo) {
err := t.initialize(ti.Ctx)
if err != nil {
panic(err)
}
} | go | {
"resource": ""
} |
q11582 | getToolContentsImpl | train | func getToolContentsImpl() (contents []byte, err error) {
// Fast path: has the user set the flag?
if *fToolPath != "" {
contents, err = ioutil.ReadFile(*fToolPath)
if err != nil {
err = fmt.Errorf("Reading mount_sample contents: %v", err)
return
}
return
}
// Create a temporary directory into which we will compile the tool.
tempDir, err := ioutil.TempDir("", "sample_test")
if err != nil {
err = fmt.Errorf("TempDir: %v", err)
return
}
toolPath := path.Join(tempDir, "mount_sample")
// Ensure that we kill the temporary directory when we're finished here.
defer os.RemoveAll(tempDir)
// Run "go build".
cmd := exec.Command(
"go",
"build",
"-o",
toolPath,
"github.com/jacobsa/fuse/samples/mount_sample")
output, err := cmd.CombinedOutput()
if err != nil {
err = fmt.Errorf(
"mount_sample exited with %v, output:\n%s",
err,
string(output))
return
}
// Slurp the tool contents.
contents, err = ioutil.ReadFile(toolPath)
if err != nil {
err = fmt.Errorf("ReadFile: %v", err)
return
}
return
} | go | {
"resource": ""
} |
q11583 | getToolContents | train | func getToolContents() (contents []byte, err error) {
// Get hold of the binary contents, if we haven't yet.
getToolContents_Once.Do(func() {
getToolContents_Contents, getToolContents_Err = getToolContentsImpl()
})
contents, err = getToolContents_Contents, getToolContents_Err
return
} | go | {
"resource": ""
} |
q11584 | NewLineScanner | train | func NewLineScanner(r io.Reader) *LineScanner {
br := bufio.NewReader(r)
ls := &LineScanner{
Reader: br,
}
return ls
} | go | {
"resource": ""
} |
q11585 | Scan | train | func (ls *LineScanner) Scan() bool {
if ls.text, _, ls.err = ls.Reader.ReadLine(); ls.err != nil {
if ls.err == io.EOF {
ls.err = nil
}
return false
}
ls.lnum++
return true
} | go | {
"resource": ""
} |
q11586 | Scan | train | func (lex *GotestLexer) Scan() bool {
if !lex.scanner.Scan() {
return false
}
if lex.scanner.Err() != nil {
return false
}
line := lex.scanner.Text()
lnum := lex.scanner.Line()
found := false
for _, typ := range gtTypes {
if typ.re.MatchString(line) {
found = true
lex.tok = &Token{lnum, typ.typ, line}
break
}
}
if !found {
lex.tok = &Token{lnum, DataToken, line}
}
return true
} | go | {
"resource": ""
} |
q11587 | hasDatarace | train | func hasDatarace(lines []string) bool {
for _, line := range lines {
if matchDatarace(line) {
return true
}
}
return false
} | go | {
"resource": ""
} |
q11588 | numStatus | train | func (suite *Suite) numStatus(status Status) int {
count := 0
for _, test := range suite.Tests {
if test.Status == status {
count++
}
}
return count
} | go | {
"resource": ""
} |
q11589 | HasFailures | train | func (s Suites) HasFailures() bool {
for _, suite := range s {
if suite.NumFailed() > 0 {
return true
}
}
return false
} | go | {
"resource": ""
} |
q11590 | Push | train | func (s *SuiteStack) Push(n *Suite) {
s.nodes = append(s.nodes[:s.count], n)
s.count++
} | go | {
"resource": ""
} |
q11591 | Pop | train | func (s *SuiteStack) Pop() *Suite {
if s.count == 0 {
return nil
}
s.count--
return s.nodes[s.count]
} | go | {
"resource": ""
} |
q11592 | NewGtParser | train | func NewGtParser(in io.Reader) Parser {
return &GtParser{
suite: nil,
tests: make(map[string]*Test),
lex: NewGotestLexer(in),
}
} | go | {
"resource": ""
} |
q11593 | validateArgs | train | func validateArgs() error {
if flag.NArg() > 0 {
return fmt.Errorf("%s does not take parameters (did you mean -input?)", os.Args[0])
}
if args.bambooOut && args.xunitnetOut {
return fmt.Errorf("-bamboo and -xunitnet are mutually exclusive")
}
return nil
} | go | {
"resource": ""
} |
q11594 | getInput | train | func getInput(filename string) (*os.File, error) {
if filename == "-" || filename == "" {
return os.Stdin, nil
}
return os.Open(filename)
} | go | {
"resource": ""
} |
q11595 | getOutput | train | func getOutput(filename string) (*os.File, error) {
if filename == "-" || filename == "" {
return os.Stdout, nil
}
return os.Create(filename)
} | go | {
"resource": ""
} |
q11596 | getIO | train | func getIO(inFile, outFile string) (*os.File, io.Writer, error) {
input, err := getInput(inFile)
if err != nil {
return nil, nil, fmt.Errorf("can't open %s for reading: %s", inFile, err)
}
output, err := getOutput(outFile)
if err != nil {
return nil, nil, fmt.Errorf("can't open %s for writing: %s", outFile, err)
}
return input, output, nil
} | go | {
"resource": ""
} |
q11597 | calcTotals | train | func (r *TestResults) calcTotals() {
totalTime, _ := strconv.ParseFloat(r.Time, 64)
for _, suite := range r.Suites {
r.NumPassed += suite.NumPassed()
r.NumFailed += suite.NumFailed()
r.NumSkipped += suite.NumSkipped()
suiteTime, _ := strconv.ParseFloat(suite.Time, 64)
totalTime += suiteTime
r.Time = fmt.Sprintf("%.3f", totalTime)
}
r.Len = r.NumPassed + r.NumSkipped + r.NumFailed
} | go | {
"resource": ""
} |
q11598 | WriteXML | train | func WriteXML(suites []*Suite, out io.Writer, xmlTemplate string, testTime time.Time) {
testsResult := TestResults{
Suites: suites,
Assembly: suites[len(suites)-1].Name,
RunDate: testTime.Format("2006-01-02"),
RunTime: testTime.Format("15:04:05"),
Skipped: Skipped,
Passed: Passed,
Failed: Failed,
}
testsResult.calcTotals()
t := template.New("test template").Funcs(template.FuncMap{
"escape": escapeForXML,
})
t, err := t.Parse(xml.Header + xmlTemplate)
if err != nil {
fmt.Printf("Error in parse %v\n", err)
return
}
err = t.Execute(out, testsResult)
if err != nil {
fmt.Printf("Error in execute %v\n", err)
return
}
} | go | {
"resource": ""
} |
q11599 | Report | train | func Report(ctx context.Context, r *ReportParams) error {
if disabled := os.Getenv("CHECKPOINT_DISABLE"); disabled != "" {
return nil
}
req, err := ReportRequest(r)
if err != nil {
return err
}
client := cleanhttp.DefaultClient()
resp, err := client.Do(req.WithContext(ctx))
if err != nil {
return err
}
if resp.StatusCode != 201 {
return fmt.Errorf("Unknown status: %d", resp.StatusCode)
}
return nil
} | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.