id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
11,500 | miekg/pkcs11 | params.go | Free | func (p *GCMParams) Free() {
if p == nil || p.arena == nil {
return
}
p.arena.Free()
p.params = nil
p.arena = nil
} | go | func (p *GCMParams) Free() {
if p == nil || p.arena == nil {
return
}
p.arena.Free()
p.params = nil
p.arena = nil
} | [
"func",
"(",
"p",
"*",
"GCMParams",
")",
"Free",
"(",
")",
"{",
"if",
"p",
"==",
"nil",
"||",
"p",
".",
"arena",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"p",
".",
"arena",
".",
"Free",
"(",
")",
"\n",
"p",
".",
"params",
"=",
"nil",
"\n",
"p",
".",
"arena",
"=",
"nil",
"\n",
"}"
]
| // Free deallocates the memory reserved for the HSM to write back the actual IV.
//
// This must be called after the entire operation is complete, i.e. after
// Encrypt or EncryptFinal. It is safe to call Free multiple times. | [
"Free",
"deallocates",
"the",
"memory",
"reserved",
"for",
"the",
"HSM",
"to",
"write",
"back",
"the",
"actual",
"IV",
".",
"This",
"must",
"be",
"called",
"after",
"the",
"entire",
"operation",
"is",
"complete",
"i",
".",
"e",
".",
"after",
"Encrypt",
"or",
"EncryptFinal",
".",
"It",
"is",
"safe",
"to",
"call",
"Free",
"multiple",
"times",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/params.go#L108-L115 |
11,501 | miekg/pkcs11 | params.go | NewPSSParams | 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 | 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)))
} | [
"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",
")",
",",
"}",
"\n",
"return",
"C",
".",
"GoBytes",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"p",
")",
",",
"C",
".",
"int",
"(",
"unsafe",
".",
"Sizeof",
"(",
"p",
")",
")",
")",
"\n",
"}"
]
| // NewPSSParams creates a CK_RSA_PKCS_PSS_PARAMS structure and returns it as a byte array for use with the CKM_RSA_PKCS_PSS mechanism. | [
"NewPSSParams",
"creates",
"a",
"CK_RSA_PKCS_PSS_PARAMS",
"structure",
"and",
"returns",
"it",
"as",
"a",
"byte",
"array",
"for",
"use",
"with",
"the",
"CKM_RSA_PKCS_PSS",
"mechanism",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/params.go#L118-L125 |
11,502 | miekg/pkcs11 | params.go | NewOAEPParams | func NewOAEPParams(hashAlg, mgf, sourceType uint, sourceData []byte) *OAEPParams {
return &OAEPParams{
HashAlg: hashAlg,
MGF: mgf,
SourceType: sourceType,
SourceData: sourceData,
}
} | go | func NewOAEPParams(hashAlg, mgf, sourceType uint, sourceData []byte) *OAEPParams {
return &OAEPParams{
HashAlg: hashAlg,
MGF: mgf,
SourceType: sourceType,
SourceData: sourceData,
}
} | [
"func",
"NewOAEPParams",
"(",
"hashAlg",
",",
"mgf",
",",
"sourceType",
"uint",
",",
"sourceData",
"[",
"]",
"byte",
")",
"*",
"OAEPParams",
"{",
"return",
"&",
"OAEPParams",
"{",
"HashAlg",
":",
"hashAlg",
",",
"MGF",
":",
"mgf",
",",
"SourceType",
":",
"sourceType",
",",
"SourceData",
":",
"sourceData",
",",
"}",
"\n",
"}"
]
| // NewOAEPParams creates a CK_RSA_PKCS_OAEP_PARAMS structure suitable for use with the CKM_RSA_PKCS_OAEP mechanism. | [
"NewOAEPParams",
"creates",
"a",
"CK_RSA_PKCS_OAEP_PARAMS",
"structure",
"suitable",
"for",
"use",
"with",
"the",
"CKM_RSA_PKCS_OAEP",
"mechanism",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/params.go#L136-L143 |
11,503 | miekg/pkcs11 | params.go | NewECDH1DeriveParams | func NewECDH1DeriveParams(kdf uint, sharedData []byte, publicKeyData []byte) *ECDH1DeriveParams {
return &ECDH1DeriveParams{
KDF: kdf,
SharedData: sharedData,
PublicKeyData: publicKeyData,
}
} | go | func NewECDH1DeriveParams(kdf uint, sharedData []byte, publicKeyData []byte) *ECDH1DeriveParams {
return &ECDH1DeriveParams{
KDF: kdf,
SharedData: sharedData,
PublicKeyData: publicKeyData,
}
} | [
"func",
"NewECDH1DeriveParams",
"(",
"kdf",
"uint",
",",
"sharedData",
"[",
"]",
"byte",
",",
"publicKeyData",
"[",
"]",
"byte",
")",
"*",
"ECDH1DeriveParams",
"{",
"return",
"&",
"ECDH1DeriveParams",
"{",
"KDF",
":",
"kdf",
",",
"SharedData",
":",
"sharedData",
",",
"PublicKeyData",
":",
"publicKeyData",
",",
"}",
"\n",
"}"
]
| // NewECDH1DeriveParams creates a CK_ECDH1_DERIVE_PARAMS structure suitable for use with the CKM_ECDH1_DERIVE mechanism. | [
"NewECDH1DeriveParams",
"creates",
"a",
"CK_ECDH1_DERIVE_PARAMS",
"structure",
"suitable",
"for",
"use",
"with",
"the",
"CKM_ECDH1_DERIVE",
"mechanism",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/params.go#L167-L173 |
11,504 | miekg/pkcs11 | pkcs11.go | Initialize | func (c *Ctx) Initialize() error {
e := C.Initialize(c.ctx)
return toError(e)
} | go | func (c *Ctx) Initialize() error {
e := C.Initialize(c.ctx)
return toError(e)
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"Initialize",
"(",
")",
"error",
"{",
"e",
":=",
"C",
".",
"Initialize",
"(",
"c",
".",
"ctx",
")",
"\n",
"return",
"toError",
"(",
"e",
")",
"\n",
"}"
]
| // Initialize initializes the Cryptoki library. | [
"Initialize",
"initializes",
"the",
"Cryptoki",
"library",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L804-L807 |
11,505 | miekg/pkcs11 | pkcs11.go | Finalize | func (c *Ctx) Finalize() error {
if c.ctx == nil {
return toError(CKR_CRYPTOKI_NOT_INITIALIZED)
}
e := C.Finalize(c.ctx)
return toError(e)
} | go | func (c *Ctx) Finalize() error {
if c.ctx == nil {
return toError(CKR_CRYPTOKI_NOT_INITIALIZED)
}
e := C.Finalize(c.ctx)
return toError(e)
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"Finalize",
"(",
")",
"error",
"{",
"if",
"c",
".",
"ctx",
"==",
"nil",
"{",
"return",
"toError",
"(",
"CKR_CRYPTOKI_NOT_INITIALIZED",
")",
"\n",
"}",
"\n",
"e",
":=",
"C",
".",
"Finalize",
"(",
"c",
".",
"ctx",
")",
"\n",
"return",
"toError",
"(",
"e",
")",
"\n",
"}"
]
| // Finalize indicates that an application is done with the Cryptoki library. | [
"Finalize",
"indicates",
"that",
"an",
"application",
"is",
"done",
"with",
"the",
"Cryptoki",
"library",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L810-L816 |
11,506 | miekg/pkcs11 | pkcs11.go | GetInfo | 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 | 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)
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"GetInfo",
"(",
")",
"(",
"Info",
",",
"error",
")",
"{",
"var",
"p",
"C",
".",
"ckInfo",
"\n",
"e",
":=",
"C",
".",
"GetInfo",
"(",
"c",
".",
"ctx",
",",
"&",
"p",
")",
"\n",
"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",
")",
",",
"}",
"\n",
"return",
"i",
",",
"toError",
"(",
"e",
")",
"\n",
"}"
]
| // GetInfo returns general information about Cryptoki. | [
"GetInfo",
"returns",
"general",
"information",
"about",
"Cryptoki",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L819-L830 |
11,507 | miekg/pkcs11 | pkcs11.go | GetSlotList | 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 | 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
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"GetSlotList",
"(",
"tokenPresent",
"bool",
")",
"(",
"[",
"]",
"uint",
",",
"error",
")",
"{",
"var",
"(",
"slotList",
"C",
".",
"CK_ULONG_PTR",
"\n",
"ulCount",
"C",
".",
"CK_ULONG",
"\n",
")",
"\n",
"e",
":=",
"C",
".",
"GetSlotList",
"(",
"c",
".",
"ctx",
",",
"cBBool",
"(",
"tokenPresent",
")",
",",
"&",
"slotList",
",",
"&",
"ulCount",
")",
"\n",
"if",
"toError",
"(",
"e",
")",
"!=",
"nil",
"{",
"return",
"nil",
",",
"toError",
"(",
"e",
")",
"\n",
"}",
"\n",
"l",
":=",
"toList",
"(",
"slotList",
",",
"ulCount",
")",
"\n",
"return",
"l",
",",
"nil",
"\n",
"}"
]
| // GetSlotList obtains a list of slots in the system. | [
"GetSlotList",
"obtains",
"a",
"list",
"of",
"slots",
"in",
"the",
"system",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L833-L844 |
11,508 | miekg/pkcs11 | pkcs11.go | GetSlotInfo | 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 | 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)
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"GetSlotInfo",
"(",
"slotID",
"uint",
")",
"(",
"SlotInfo",
",",
"error",
")",
"{",
"var",
"csi",
"C",
".",
"CK_SLOT_INFO",
"\n",
"e",
":=",
"C",
".",
"GetSlotInfo",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_ULONG",
"(",
"slotID",
")",
",",
"&",
"csi",
")",
"\n",
"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",
")",
",",
"}",
"\n",
"return",
"s",
",",
"toError",
"(",
"e",
")",
"\n",
"}"
]
| // GetSlotInfo obtains information about a particular slot in the system. | [
"GetSlotInfo",
"obtains",
"information",
"about",
"a",
"particular",
"slot",
"in",
"the",
"system",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L847-L858 |
11,509 | miekg/pkcs11 | pkcs11.go | GetTokenInfo | 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 | 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)
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"GetTokenInfo",
"(",
"slotID",
"uint",
")",
"(",
"TokenInfo",
",",
"error",
")",
"{",
"var",
"cti",
"C",
".",
"CK_TOKEN_INFO",
"\n",
"e",
":=",
"C",
".",
"GetTokenInfo",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_ULONG",
"(",
"slotID",
")",
",",
"&",
"cti",
")",
"\n",
"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",
")",
")",
",",
"\"",
"\"",
")",
",",
"}",
"\n",
"return",
"s",
",",
"toError",
"(",
"e",
")",
"\n",
"}"
]
| // GetTokenInfo obtains information about a particular token
// in the system. | [
"GetTokenInfo",
"obtains",
"information",
"about",
"a",
"particular",
"token",
"in",
"the",
"system",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L862-L886 |
11,510 | miekg/pkcs11 | pkcs11.go | GetMechanismList | 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 | 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
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"GetMechanismList",
"(",
"slotID",
"uint",
")",
"(",
"[",
"]",
"*",
"Mechanism",
",",
"error",
")",
"{",
"var",
"(",
"mech",
"C",
".",
"CK_ULONG_PTR",
"// in pkcs#11 we're all CK_ULONGs \\o/",
"\n",
"mechlen",
"C",
".",
"CK_ULONG",
"\n",
")",
"\n",
"e",
":=",
"C",
".",
"GetMechanismList",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_ULONG",
"(",
"slotID",
")",
",",
"&",
"mech",
",",
"&",
"mechlen",
")",
"\n",
"if",
"toError",
"(",
"e",
")",
"!=",
"nil",
"{",
"return",
"nil",
",",
"toError",
"(",
"e",
")",
"\n",
"}",
"\n",
"// Although the function returns only type, cast them back into real",
"// attributes as this is used in other functions.",
"m",
":=",
"make",
"(",
"[",
"]",
"*",
"Mechanism",
",",
"int",
"(",
"mechlen",
")",
")",
"\n",
"for",
"i",
",",
"typ",
":=",
"range",
"toList",
"(",
"mech",
",",
"mechlen",
")",
"{",
"m",
"[",
"i",
"]",
"=",
"NewMechanism",
"(",
"typ",
",",
"nil",
")",
"\n",
"}",
"\n",
"return",
"m",
",",
"nil",
"\n",
"}"
]
| // GetMechanismList obtains a list of mechanism types supported by a token. | [
"GetMechanismList",
"obtains",
"a",
"list",
"of",
"mechanism",
"types",
"supported",
"by",
"a",
"token",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L889-L905 |
11,511 | miekg/pkcs11 | pkcs11.go | GetMechanismInfo | 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 | 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)
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"GetMechanismInfo",
"(",
"slotID",
"uint",
",",
"m",
"[",
"]",
"*",
"Mechanism",
")",
"(",
"MechanismInfo",
",",
"error",
")",
"{",
"var",
"cm",
"C",
".",
"CK_MECHANISM_INFO",
"\n",
"e",
":=",
"C",
".",
"GetMechanismInfo",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_ULONG",
"(",
"slotID",
")",
",",
"C",
".",
"CK_MECHANISM_TYPE",
"(",
"m",
"[",
"0",
"]",
".",
"Mechanism",
")",
",",
"C",
".",
"CK_MECHANISM_INFO_PTR",
"(",
"&",
"cm",
")",
")",
"\n",
"mi",
":=",
"MechanismInfo",
"{",
"MinKeySize",
":",
"uint",
"(",
"cm",
".",
"ulMinKeySize",
")",
",",
"MaxKeySize",
":",
"uint",
"(",
"cm",
".",
"ulMaxKeySize",
")",
",",
"Flags",
":",
"uint",
"(",
"cm",
".",
"flags",
")",
",",
"}",
"\n",
"return",
"mi",
",",
"toError",
"(",
"e",
")",
"\n",
"}"
]
| // GetMechanismInfo obtains information about a particular
// mechanism possibly supported by a token. | [
"GetMechanismInfo",
"obtains",
"information",
"about",
"a",
"particular",
"mechanism",
"possibly",
"supported",
"by",
"a",
"token",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L909-L919 |
11,512 | miekg/pkcs11 | pkcs11.go | InitToken | 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 | 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)
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"InitToken",
"(",
"slotID",
"uint",
",",
"pin",
"string",
",",
"label",
"string",
")",
"error",
"{",
"p",
":=",
"C",
".",
"CString",
"(",
"pin",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"p",
")",
")",
"\n",
"ll",
":=",
"len",
"(",
"label",
")",
"\n",
"for",
"ll",
"<",
"32",
"{",
"label",
"+=",
"\"",
"\"",
"\n",
"ll",
"++",
"\n",
"}",
"\n",
"l",
":=",
"C",
".",
"CString",
"(",
"label",
"[",
":",
"32",
"]",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"l",
")",
")",
"\n",
"e",
":=",
"C",
".",
"InitToken",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_ULONG",
"(",
"slotID",
")",
",",
"p",
",",
"C",
".",
"CK_ULONG",
"(",
"len",
"(",
"pin",
")",
")",
",",
"l",
")",
"\n",
"return",
"toError",
"(",
"e",
")",
"\n",
"}"
]
| // InitToken initializes a token. The label must be 32 characters
// long, it is blank padded if it is not. If it is longer it is capped
// to 32 characters. | [
"InitToken",
"initializes",
"a",
"token",
".",
"The",
"label",
"must",
"be",
"32",
"characters",
"long",
"it",
"is",
"blank",
"padded",
"if",
"it",
"is",
"not",
".",
"If",
"it",
"is",
"longer",
"it",
"is",
"capped",
"to",
"32",
"characters",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L924-L936 |
11,513 | miekg/pkcs11 | pkcs11.go | InitPIN | 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 | 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)
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"InitPIN",
"(",
"sh",
"SessionHandle",
",",
"pin",
"string",
")",
"error",
"{",
"p",
":=",
"C",
".",
"CString",
"(",
"pin",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"p",
")",
")",
"\n",
"e",
":=",
"C",
".",
"InitPIN",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_SESSION_HANDLE",
"(",
"sh",
")",
",",
"p",
",",
"C",
".",
"CK_ULONG",
"(",
"len",
"(",
"pin",
")",
")",
")",
"\n",
"return",
"toError",
"(",
"e",
")",
"\n",
"}"
]
| // InitPIN initializes the normal user's PIN. | [
"InitPIN",
"initializes",
"the",
"normal",
"user",
"s",
"PIN",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L939-L944 |
11,514 | miekg/pkcs11 | pkcs11.go | SetPIN | 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 | 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)
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"SetPIN",
"(",
"sh",
"SessionHandle",
",",
"oldpin",
"string",
",",
"newpin",
"string",
")",
"error",
"{",
"old",
":=",
"C",
".",
"CString",
"(",
"oldpin",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"old",
")",
")",
"\n",
"new",
":=",
"C",
".",
"CString",
"(",
"newpin",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"new",
")",
")",
"\n",
"e",
":=",
"C",
".",
"SetPIN",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_SESSION_HANDLE",
"(",
"sh",
")",
",",
"old",
",",
"C",
".",
"CK_ULONG",
"(",
"len",
"(",
"oldpin",
")",
")",
",",
"new",
",",
"C",
".",
"CK_ULONG",
"(",
"len",
"(",
"newpin",
")",
")",
")",
"\n",
"return",
"toError",
"(",
"e",
")",
"\n",
"}"
]
| // SetPIN modifies the PIN of the user who is logged in. | [
"SetPIN",
"modifies",
"the",
"PIN",
"of",
"the",
"user",
"who",
"is",
"logged",
"in",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L947-L954 |
11,515 | miekg/pkcs11 | pkcs11.go | CloseAllSessions | 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 | 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)
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"CloseAllSessions",
"(",
"slotID",
"uint",
")",
"error",
"{",
"if",
"c",
".",
"ctx",
"==",
"nil",
"{",
"return",
"toError",
"(",
"CKR_CRYPTOKI_NOT_INITIALIZED",
")",
"\n",
"}",
"\n",
"e",
":=",
"C",
".",
"CloseAllSessions",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_ULONG",
"(",
"slotID",
")",
")",
"\n",
"return",
"toError",
"(",
"e",
")",
"\n",
"}"
]
| // CloseAllSessions closes all sessions with a token. | [
"CloseAllSessions",
"closes",
"all",
"sessions",
"with",
"a",
"token",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L973-L979 |
11,516 | miekg/pkcs11 | pkcs11.go | GetSessionInfo | 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 | 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)
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"GetSessionInfo",
"(",
"sh",
"SessionHandle",
")",
"(",
"SessionInfo",
",",
"error",
")",
"{",
"var",
"csi",
"C",
".",
"CK_SESSION_INFO",
"\n",
"e",
":=",
"C",
".",
"GetSessionInfo",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_SESSION_HANDLE",
"(",
"sh",
")",
",",
"&",
"csi",
")",
"\n",
"s",
":=",
"SessionInfo",
"{",
"SlotID",
":",
"uint",
"(",
"csi",
".",
"slotID",
")",
",",
"State",
":",
"uint",
"(",
"csi",
".",
"state",
")",
",",
"Flags",
":",
"uint",
"(",
"csi",
".",
"flags",
")",
",",
"DeviceError",
":",
"uint",
"(",
"csi",
".",
"ulDeviceError",
")",
",",
"}",
"\n",
"return",
"s",
",",
"toError",
"(",
"e",
")",
"\n",
"}"
]
| // GetSessionInfo obtains information about the session. | [
"GetSessionInfo",
"obtains",
"information",
"about",
"the",
"session",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L982-L991 |
11,517 | miekg/pkcs11 | pkcs11.go | GetOperationState | 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 | 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
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"GetOperationState",
"(",
"sh",
"SessionHandle",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"(",
"state",
"C",
".",
"CK_BYTE_PTR",
"\n",
"statelen",
"C",
".",
"CK_ULONG",
"\n",
")",
"\n",
"e",
":=",
"C",
".",
"GetOperationState",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_SESSION_HANDLE",
"(",
"sh",
")",
",",
"&",
"state",
",",
"&",
"statelen",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"state",
")",
")",
"\n",
"if",
"toError",
"(",
"e",
")",
"!=",
"nil",
"{",
"return",
"nil",
",",
"toError",
"(",
"e",
")",
"\n",
"}",
"\n",
"b",
":=",
"C",
".",
"GoBytes",
"(",
"unsafe",
".",
"Pointer",
"(",
"state",
")",
",",
"C",
".",
"int",
"(",
"statelen",
")",
")",
"\n",
"return",
"b",
",",
"nil",
"\n",
"}"
]
| // GetOperationState obtains the state of the cryptographic operation in a session. | [
"GetOperationState",
"obtains",
"the",
"state",
"of",
"the",
"cryptographic",
"operation",
"in",
"a",
"session",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L994-L1006 |
11,518 | miekg/pkcs11 | pkcs11.go | SetOperationState | 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 | 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)
} | [
"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",
")",
")",
"\n",
"return",
"toError",
"(",
"e",
")",
"\n",
"}"
]
| // SetOperationState restores the state of the cryptographic operation in a session. | [
"SetOperationState",
"restores",
"the",
"state",
"of",
"the",
"cryptographic",
"operation",
"in",
"a",
"session",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L1009-L1013 |
11,519 | miekg/pkcs11 | pkcs11.go | Login | 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 | 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)
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"Login",
"(",
"sh",
"SessionHandle",
",",
"userType",
"uint",
",",
"pin",
"string",
")",
"error",
"{",
"p",
":=",
"C",
".",
"CString",
"(",
"pin",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"p",
")",
")",
"\n",
"e",
":=",
"C",
".",
"Login",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_SESSION_HANDLE",
"(",
"sh",
")",
",",
"C",
".",
"CK_USER_TYPE",
"(",
"userType",
")",
",",
"p",
",",
"C",
".",
"CK_ULONG",
"(",
"len",
"(",
"pin",
")",
")",
")",
"\n",
"return",
"toError",
"(",
"e",
")",
"\n",
"}"
]
| // Login logs a user into a token. | [
"Login",
"logs",
"a",
"user",
"into",
"a",
"token",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L1016-L1021 |
11,520 | miekg/pkcs11 | pkcs11.go | Logout | 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 | 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)
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"Logout",
"(",
"sh",
"SessionHandle",
")",
"error",
"{",
"if",
"c",
".",
"ctx",
"==",
"nil",
"{",
"return",
"toError",
"(",
"CKR_CRYPTOKI_NOT_INITIALIZED",
")",
"\n",
"}",
"\n",
"e",
":=",
"C",
".",
"Logout",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_SESSION_HANDLE",
"(",
"sh",
")",
")",
"\n",
"return",
"toError",
"(",
"e",
")",
"\n",
"}"
]
| // Logout logs a user out from a token. | [
"Logout",
"logs",
"a",
"user",
"out",
"from",
"a",
"token",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L1024-L1030 |
11,521 | miekg/pkcs11 | pkcs11.go | CreateObject | 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 | 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
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"CreateObject",
"(",
"sh",
"SessionHandle",
",",
"temp",
"[",
"]",
"*",
"Attribute",
")",
"(",
"ObjectHandle",
",",
"error",
")",
"{",
"var",
"obj",
"C",
".",
"CK_OBJECT_HANDLE",
"\n",
"arena",
",",
"t",
",",
"tcount",
":=",
"cAttributeList",
"(",
"temp",
")",
"\n",
"defer",
"arena",
".",
"Free",
"(",
")",
"\n",
"e",
":=",
"C",
".",
"CreateObject",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_SESSION_HANDLE",
"(",
"sh",
")",
",",
"t",
",",
"tcount",
",",
"C",
".",
"CK_OBJECT_HANDLE_PTR",
"(",
"&",
"obj",
")",
")",
"\n",
"e1",
":=",
"toError",
"(",
"e",
")",
"\n",
"if",
"e1",
"==",
"nil",
"{",
"return",
"ObjectHandle",
"(",
"obj",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"0",
",",
"e1",
"\n",
"}"
]
| // CreateObject creates a new object. | [
"CreateObject",
"creates",
"a",
"new",
"object",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L1033-L1043 |
11,522 | miekg/pkcs11 | pkcs11.go | GetObjectSize | 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 | 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)
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"GetObjectSize",
"(",
"sh",
"SessionHandle",
",",
"oh",
"ObjectHandle",
")",
"(",
"uint",
",",
"error",
")",
"{",
"var",
"size",
"C",
".",
"CK_ULONG",
"\n",
"e",
":=",
"C",
".",
"GetObjectSize",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_SESSION_HANDLE",
"(",
"sh",
")",
",",
"C",
".",
"CK_OBJECT_HANDLE",
"(",
"oh",
")",
",",
"&",
"size",
")",
"\n",
"return",
"uint",
"(",
"size",
")",
",",
"toError",
"(",
"e",
")",
"\n",
"}"
]
| // GetObjectSize gets the size of an object in bytes. | [
"GetObjectSize",
"gets",
"the",
"size",
"of",
"an",
"object",
"in",
"bytes",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L1066-L1070 |
11,523 | miekg/pkcs11 | pkcs11.go | SetAttributeValue | 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 | 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)
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"SetAttributeValue",
"(",
"sh",
"SessionHandle",
",",
"o",
"ObjectHandle",
",",
"a",
"[",
"]",
"*",
"Attribute",
")",
"error",
"{",
"arena",
",",
"pa",
",",
"palen",
":=",
"cAttributeList",
"(",
"a",
")",
"\n",
"defer",
"arena",
".",
"Free",
"(",
")",
"\n",
"e",
":=",
"C",
".",
"SetAttributeValue",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_SESSION_HANDLE",
"(",
"sh",
")",
",",
"C",
".",
"CK_OBJECT_HANDLE",
"(",
"o",
")",
",",
"pa",
",",
"palen",
")",
"\n",
"return",
"toError",
"(",
"e",
")",
"\n",
"}"
]
| // SetAttributeValue modifies the value of one or more object attributes | [
"SetAttributeValue",
"modifies",
"the",
"value",
"of",
"one",
"or",
"more",
"object",
"attributes"
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L1099-L1104 |
11,524 | miekg/pkcs11 | pkcs11.go | FindObjects | 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 | 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
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"FindObjects",
"(",
"sh",
"SessionHandle",
",",
"max",
"int",
")",
"(",
"[",
"]",
"ObjectHandle",
",",
"bool",
",",
"error",
")",
"{",
"var",
"(",
"objectList",
"C",
".",
"CK_OBJECT_HANDLE_PTR",
"\n",
"ulCount",
"C",
".",
"CK_ULONG",
"\n",
")",
"\n",
"e",
":=",
"C",
".",
"FindObjects",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_SESSION_HANDLE",
"(",
"sh",
")",
",",
"&",
"objectList",
",",
"C",
".",
"CK_ULONG",
"(",
"max",
")",
",",
"&",
"ulCount",
")",
"\n",
"if",
"toError",
"(",
"e",
")",
"!=",
"nil",
"{",
"return",
"nil",
",",
"false",
",",
"toError",
"(",
"e",
")",
"\n",
"}",
"\n",
"l",
":=",
"toList",
"(",
"C",
".",
"CK_ULONG_PTR",
"(",
"unsafe",
".",
"Pointer",
"(",
"objectList",
")",
")",
",",
"ulCount",
")",
"\n",
"// 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",
")",
")",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"l",
"{",
"o",
"[",
"i",
"]",
"=",
"ObjectHandle",
"(",
"v",
")",
"\n",
"}",
"\n",
"return",
"o",
",",
"ulCount",
">",
"C",
".",
"CK_ULONG",
"(",
"max",
")",
",",
"nil",
"\n",
"}"
]
| // FindObjects continues a search for token and session
// objects that match a template, obtaining additional object
// handles. Calling the function repeatedly may yield additional results until
// an empty slice is returned.
//
// The returned boolean value is deprecated and should be ignored. | [
"FindObjects",
"continues",
"a",
"search",
"for",
"token",
"and",
"session",
"objects",
"that",
"match",
"a",
"template",
"obtaining",
"additional",
"object",
"handles",
".",
"Calling",
"the",
"function",
"repeatedly",
"may",
"yield",
"additional",
"results",
"until",
"an",
"empty",
"slice",
"is",
"returned",
".",
"The",
"returned",
"boolean",
"value",
"is",
"deprecated",
"and",
"should",
"be",
"ignored",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L1121-L1138 |
11,525 | miekg/pkcs11 | pkcs11.go | Encrypt | 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 | 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
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"Encrypt",
"(",
"sh",
"SessionHandle",
",",
"message",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"(",
"enc",
"C",
".",
"CK_BYTE_PTR",
"\n",
"enclen",
"C",
".",
"CK_ULONG",
"\n",
")",
"\n",
"e",
":=",
"C",
".",
"Encrypt",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_SESSION_HANDLE",
"(",
"sh",
")",
",",
"cMessage",
"(",
"message",
")",
",",
"C",
".",
"CK_ULONG",
"(",
"len",
"(",
"message",
")",
")",
",",
"&",
"enc",
",",
"&",
"enclen",
")",
"\n",
"if",
"toError",
"(",
"e",
")",
"!=",
"nil",
"{",
"return",
"nil",
",",
"toError",
"(",
"e",
")",
"\n",
"}",
"\n",
"s",
":=",
"C",
".",
"GoBytes",
"(",
"unsafe",
".",
"Pointer",
"(",
"enc",
")",
",",
"C",
".",
"int",
"(",
"enclen",
")",
")",
"\n",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"enc",
")",
")",
"\n",
"return",
"s",
",",
"nil",
"\n",
"}"
]
| // Encrypt encrypts single-part data. | [
"Encrypt",
"encrypts",
"single",
"-",
"part",
"data",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L1155-L1167 |
11,526 | miekg/pkcs11 | pkcs11.go | DecryptFinal | 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 | 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
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"DecryptFinal",
"(",
"sh",
"SessionHandle",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"(",
"plain",
"C",
".",
"CK_BYTE_PTR",
"\n",
"plainlen",
"C",
".",
"CK_ULONG",
"\n",
")",
"\n",
"e",
":=",
"C",
".",
"DecryptFinal",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_SESSION_HANDLE",
"(",
"sh",
")",
",",
"&",
"plain",
",",
"&",
"plainlen",
")",
"\n",
"if",
"toError",
"(",
"e",
")",
"!=",
"nil",
"{",
"return",
"nil",
",",
"toError",
"(",
"e",
")",
"\n",
"}",
"\n",
"h",
":=",
"C",
".",
"GoBytes",
"(",
"unsafe",
".",
"Pointer",
"(",
"plain",
")",
",",
"C",
".",
"int",
"(",
"plainlen",
")",
")",
"\n",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"plain",
")",
")",
"\n",
"return",
"h",
",",
"nil",
"\n",
"}"
]
| // DecryptFinal finishes a multiple-part decryption operation. | [
"DecryptFinal",
"finishes",
"a",
"multiple",
"-",
"part",
"decryption",
"operation",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L1238-L1250 |
11,527 | miekg/pkcs11 | pkcs11.go | DigestInit | 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 | 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)
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"DigestInit",
"(",
"sh",
"SessionHandle",
",",
"m",
"[",
"]",
"*",
"Mechanism",
")",
"error",
"{",
"arena",
",",
"mech",
":=",
"cMechanism",
"(",
"m",
")",
"\n",
"defer",
"arena",
".",
"Free",
"(",
")",
"\n",
"e",
":=",
"C",
".",
"DigestInit",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_SESSION_HANDLE",
"(",
"sh",
")",
",",
"mech",
")",
"\n",
"return",
"toError",
"(",
"e",
")",
"\n",
"}"
]
| // DigestInit initializes a message-digesting operation. | [
"DigestInit",
"initializes",
"a",
"message",
"-",
"digesting",
"operation",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L1253-L1258 |
11,528 | miekg/pkcs11 | pkcs11.go | DigestUpdate | 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 | 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
} | [
"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",
")",
")",
")",
"\n",
"if",
"toError",
"(",
"e",
")",
"!=",
"nil",
"{",
"return",
"toError",
"(",
"e",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // DigestUpdate continues a multiple-part message-digesting operation. | [
"DigestUpdate",
"continues",
"a",
"multiple",
"-",
"part",
"message",
"-",
"digesting",
"operation",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L1276-L1282 |
11,529 | miekg/pkcs11 | pkcs11.go | DigestKey | 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 | 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
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"DigestKey",
"(",
"sh",
"SessionHandle",
",",
"key",
"ObjectHandle",
")",
"error",
"{",
"e",
":=",
"C",
".",
"DigestKey",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_SESSION_HANDLE",
"(",
"sh",
")",
",",
"C",
".",
"CK_OBJECT_HANDLE",
"(",
"key",
")",
")",
"\n",
"if",
"toError",
"(",
"e",
")",
"!=",
"nil",
"{",
"return",
"toError",
"(",
"e",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // DigestKey continues a multi-part message-digesting
// operation, by digesting the value of a secret key as part of
// the data already digested. | [
"DigestKey",
"continues",
"a",
"multi",
"-",
"part",
"message",
"-",
"digesting",
"operation",
"by",
"digesting",
"the",
"value",
"of",
"a",
"secret",
"key",
"as",
"part",
"of",
"the",
"data",
"already",
"digested",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L1287-L1293 |
11,530 | miekg/pkcs11 | pkcs11.go | DigestFinal | 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 | 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
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"DigestFinal",
"(",
"sh",
"SessionHandle",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"(",
"hash",
"C",
".",
"CK_BYTE_PTR",
"\n",
"hashlen",
"C",
".",
"CK_ULONG",
"\n",
")",
"\n",
"e",
":=",
"C",
".",
"DigestFinal",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_SESSION_HANDLE",
"(",
"sh",
")",
",",
"&",
"hash",
",",
"&",
"hashlen",
")",
"\n",
"if",
"toError",
"(",
"e",
")",
"!=",
"nil",
"{",
"return",
"nil",
",",
"toError",
"(",
"e",
")",
"\n",
"}",
"\n",
"h",
":=",
"C",
".",
"GoBytes",
"(",
"unsafe",
".",
"Pointer",
"(",
"hash",
")",
",",
"C",
".",
"int",
"(",
"hashlen",
")",
")",
"\n",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"hash",
")",
")",
"\n",
"return",
"h",
",",
"nil",
"\n",
"}"
]
| // DigestFinal finishes a multiple-part message-digesting operation. | [
"DigestFinal",
"finishes",
"a",
"multiple",
"-",
"part",
"message",
"-",
"digesting",
"operation",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L1296-L1308 |
11,531 | miekg/pkcs11 | pkcs11.go | SignRecover | 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 | 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
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"SignRecover",
"(",
"sh",
"SessionHandle",
",",
"data",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"(",
"sig",
"C",
".",
"CK_BYTE_PTR",
"\n",
"siglen",
"C",
".",
"CK_ULONG",
"\n",
")",
"\n",
"e",
":=",
"C",
".",
"SignRecover",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_SESSION_HANDLE",
"(",
"sh",
")",
",",
"cMessage",
"(",
"data",
")",
",",
"C",
".",
"CK_ULONG",
"(",
"len",
"(",
"data",
")",
")",
",",
"&",
"sig",
",",
"&",
"siglen",
")",
"\n",
"if",
"toError",
"(",
"e",
")",
"!=",
"nil",
"{",
"return",
"nil",
",",
"toError",
"(",
"e",
")",
"\n",
"}",
"\n",
"h",
":=",
"C",
".",
"GoBytes",
"(",
"unsafe",
".",
"Pointer",
"(",
"sig",
")",
",",
"C",
".",
"int",
"(",
"siglen",
")",
")",
"\n",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"sig",
")",
")",
"\n",
"return",
"h",
",",
"nil",
"\n",
"}"
]
| // SignRecover signs data in a single operation, where the data can be recovered from the signature. | [
"SignRecover",
"signs",
"data",
"in",
"a",
"single",
"operation",
"where",
"the",
"data",
"can",
"be",
"recovered",
"from",
"the",
"signature",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L1368-L1380 |
11,532 | miekg/pkcs11 | pkcs11.go | VerifyUpdate | 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 | 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)
} | [
"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",
")",
")",
")",
"\n",
"return",
"toError",
"(",
"e",
")",
"\n",
"}"
]
| // VerifyUpdate continues a multiple-part verification
// operation, where the signature is an appendix to the data,
// and plaintext cannot be recovered from the signature. | [
"VerifyUpdate",
"continues",
"a",
"multiple",
"-",
"part",
"verification",
"operation",
"where",
"the",
"signature",
"is",
"an",
"appendix",
"to",
"the",
"data",
"and",
"plaintext",
"cannot",
"be",
"recovered",
"from",
"the",
"signature",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L1403-L1406 |
11,533 | miekg/pkcs11 | pkcs11.go | VerifyFinal | 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 | 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)
} | [
"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",
")",
")",
")",
"\n",
"return",
"toError",
"(",
"e",
")",
"\n",
"}"
]
| // VerifyFinal finishes a multiple-part verification
// operation, checking the signature. | [
"VerifyFinal",
"finishes",
"a",
"multiple",
"-",
"part",
"verification",
"operation",
"checking",
"the",
"signature",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L1410-L1413 |
11,534 | miekg/pkcs11 | pkcs11.go | VerifyRecover | 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 | 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
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"VerifyRecover",
"(",
"sh",
"SessionHandle",
",",
"signature",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"(",
"data",
"C",
".",
"CK_BYTE_PTR",
"\n",
"datalen",
"C",
".",
"CK_ULONG",
"\n",
")",
"\n",
"e",
":=",
"C",
".",
"DecryptVerifyUpdate",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_SESSION_HANDLE",
"(",
"sh",
")",
",",
"cMessage",
"(",
"signature",
")",
",",
"C",
".",
"CK_ULONG",
"(",
"len",
"(",
"signature",
")",
")",
",",
"&",
"data",
",",
"&",
"datalen",
")",
"\n",
"if",
"toError",
"(",
"e",
")",
"!=",
"nil",
"{",
"return",
"nil",
",",
"toError",
"(",
"e",
")",
"\n",
"}",
"\n",
"h",
":=",
"C",
".",
"GoBytes",
"(",
"unsafe",
".",
"Pointer",
"(",
"data",
")",
",",
"C",
".",
"int",
"(",
"datalen",
")",
")",
"\n",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"data",
")",
")",
"\n",
"return",
"h",
",",
"nil",
"\n",
"}"
]
| // VerifyRecover verifies a signature in a single-part
// operation, where the data is recovered from the signature. | [
"VerifyRecover",
"verifies",
"a",
"signature",
"in",
"a",
"single",
"-",
"part",
"operation",
"where",
"the",
"data",
"is",
"recovered",
"from",
"the",
"signature",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L1426-L1438 |
11,535 | miekg/pkcs11 | pkcs11.go | DecryptDigestUpdate | 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 | 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
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"DecryptDigestUpdate",
"(",
"sh",
"SessionHandle",
",",
"cipher",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"(",
"part",
"C",
".",
"CK_BYTE_PTR",
"\n",
"partlen",
"C",
".",
"CK_ULONG",
"\n",
")",
"\n",
"e",
":=",
"C",
".",
"DecryptDigestUpdate",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_SESSION_HANDLE",
"(",
"sh",
")",
",",
"cMessage",
"(",
"cipher",
")",
",",
"C",
".",
"CK_ULONG",
"(",
"len",
"(",
"cipher",
")",
")",
",",
"&",
"part",
",",
"&",
"partlen",
")",
"\n",
"if",
"toError",
"(",
"e",
")",
"!=",
"nil",
"{",
"return",
"nil",
",",
"toError",
"(",
"e",
")",
"\n",
"}",
"\n",
"h",
":=",
"C",
".",
"GoBytes",
"(",
"unsafe",
".",
"Pointer",
"(",
"part",
")",
",",
"C",
".",
"int",
"(",
"partlen",
")",
")",
"\n",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"part",
")",
")",
"\n",
"return",
"h",
",",
"nil",
"\n",
"}"
]
| // DecryptDigestUpdate continues a multiple-part decryption and digesting operation. | [
"DecryptDigestUpdate",
"continues",
"a",
"multiple",
"-",
"part",
"decryption",
"and",
"digesting",
"operation",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L1456-L1468 |
11,536 | miekg/pkcs11 | pkcs11.go | SignEncryptUpdate | 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 | 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
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"SignEncryptUpdate",
"(",
"sh",
"SessionHandle",
",",
"part",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"(",
"enc",
"C",
".",
"CK_BYTE_PTR",
"\n",
"enclen",
"C",
".",
"CK_ULONG",
"\n",
")",
"\n",
"e",
":=",
"C",
".",
"SignEncryptUpdate",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_SESSION_HANDLE",
"(",
"sh",
")",
",",
"cMessage",
"(",
"part",
")",
",",
"C",
".",
"CK_ULONG",
"(",
"len",
"(",
"part",
")",
")",
",",
"&",
"enc",
",",
"&",
"enclen",
")",
"\n",
"if",
"toError",
"(",
"e",
")",
"!=",
"nil",
"{",
"return",
"nil",
",",
"toError",
"(",
"e",
")",
"\n",
"}",
"\n",
"h",
":=",
"C",
".",
"GoBytes",
"(",
"unsafe",
".",
"Pointer",
"(",
"enc",
")",
",",
"C",
".",
"int",
"(",
"enclen",
")",
")",
"\n",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"enc",
")",
")",
"\n",
"return",
"h",
",",
"nil",
"\n",
"}"
]
| // SignEncryptUpdate continues a multiple-part signing and encryption operation. | [
"SignEncryptUpdate",
"continues",
"a",
"multiple",
"-",
"part",
"signing",
"and",
"encryption",
"operation",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L1471-L1483 |
11,537 | miekg/pkcs11 | pkcs11.go | DeriveKey | 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 | 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)
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"DeriveKey",
"(",
"sh",
"SessionHandle",
",",
"m",
"[",
"]",
"*",
"Mechanism",
",",
"basekey",
"ObjectHandle",
",",
"a",
"[",
"]",
"*",
"Attribute",
")",
"(",
"ObjectHandle",
",",
"error",
")",
"{",
"var",
"key",
"C",
".",
"CK_OBJECT_HANDLE",
"\n",
"attrarena",
",",
"ac",
",",
"aclen",
":=",
"cAttributeList",
"(",
"a",
")",
"\n",
"defer",
"attrarena",
".",
"Free",
"(",
")",
"\n",
"mecharena",
",",
"mech",
":=",
"cMechanism",
"(",
"m",
")",
"\n",
"defer",
"mecharena",
".",
"Free",
"(",
")",
"\n",
"e",
":=",
"C",
".",
"DeriveKey",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_SESSION_HANDLE",
"(",
"sh",
")",
",",
"mech",
",",
"C",
".",
"CK_OBJECT_HANDLE",
"(",
"basekey",
")",
",",
"ac",
",",
"aclen",
",",
"&",
"key",
")",
"\n",
"return",
"ObjectHandle",
"(",
"key",
")",
",",
"toError",
"(",
"e",
")",
"\n",
"}"
]
| // DeriveKey derives a key from a base key, creating a new key object. | [
"DeriveKey",
"derives",
"a",
"key",
"from",
"a",
"base",
"key",
"creating",
"a",
"new",
"key",
"object",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L1564-L1572 |
11,538 | miekg/pkcs11 | pkcs11.go | SeedRandom | 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 | 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)
} | [
"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",
")",
")",
")",
"\n",
"return",
"toError",
"(",
"e",
")",
"\n",
"}"
]
| // SeedRandom mixes additional seed material into the token's
// random number generator. | [
"SeedRandom",
"mixes",
"additional",
"seed",
"material",
"into",
"the",
"token",
"s",
"random",
"number",
"generator",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L1576-L1579 |
11,539 | miekg/pkcs11 | pkcs11.go | GenerateRandom | 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 | 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
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"GenerateRandom",
"(",
"sh",
"SessionHandle",
",",
"length",
"int",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"rand",
"C",
".",
"CK_BYTE_PTR",
"\n",
"e",
":=",
"C",
".",
"GenerateRandom",
"(",
"c",
".",
"ctx",
",",
"C",
".",
"CK_SESSION_HANDLE",
"(",
"sh",
")",
",",
"&",
"rand",
",",
"C",
".",
"CK_ULONG",
"(",
"length",
")",
")",
"\n",
"if",
"toError",
"(",
"e",
")",
"!=",
"nil",
"{",
"return",
"nil",
",",
"toError",
"(",
"e",
")",
"\n",
"}",
"\n",
"h",
":=",
"C",
".",
"GoBytes",
"(",
"unsafe",
".",
"Pointer",
"(",
"rand",
")",
",",
"C",
".",
"int",
"(",
"length",
")",
")",
"\n",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"rand",
")",
")",
"\n",
"return",
"h",
",",
"nil",
"\n",
"}"
]
| // GenerateRandom generates random data. | [
"GenerateRandom",
"generates",
"random",
"data",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/pkcs11.go#L1582-L1591 |
11,540 | miekg/pkcs11 | p11/slot.go | Info | func (s Slot) Info() (pkcs11.SlotInfo, error) {
return s.ctx.GetSlotInfo(s.id)
} | go | func (s Slot) Info() (pkcs11.SlotInfo, error) {
return s.ctx.GetSlotInfo(s.id)
} | [
"func",
"(",
"s",
"Slot",
")",
"Info",
"(",
")",
"(",
"pkcs11",
".",
"SlotInfo",
",",
"error",
")",
"{",
"return",
"s",
".",
"ctx",
".",
"GetSlotInfo",
"(",
"s",
".",
"id",
")",
"\n",
"}"
]
| // Info returns information about the Slot. | [
"Info",
"returns",
"information",
"about",
"the",
"Slot",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/p11/slot.go#L12-L14 |
11,541 | miekg/pkcs11 | p11/slot.go | TokenInfo | func (s Slot) TokenInfo() (pkcs11.TokenInfo, error) {
return s.ctx.GetTokenInfo(s.id)
} | go | func (s Slot) TokenInfo() (pkcs11.TokenInfo, error) {
return s.ctx.GetTokenInfo(s.id)
} | [
"func",
"(",
"s",
"Slot",
")",
"TokenInfo",
"(",
")",
"(",
"pkcs11",
".",
"TokenInfo",
",",
"error",
")",
"{",
"return",
"s",
".",
"ctx",
".",
"GetTokenInfo",
"(",
"s",
".",
"id",
")",
"\n",
"}"
]
| // TokenInfo returns information about the token in a Slot, if applicable. | [
"TokenInfo",
"returns",
"information",
"about",
"the",
"token",
"in",
"a",
"Slot",
"if",
"applicable",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/p11/slot.go#L17-L19 |
11,542 | miekg/pkcs11 | p11/slot.go | Mechanisms | 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 | 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
} | [
"func",
"(",
"s",
"Slot",
")",
"Mechanisms",
"(",
")",
"(",
"[",
"]",
"Mechanism",
",",
"error",
")",
"{",
"list",
",",
"err",
":=",
"s",
".",
"ctx",
".",
"GetMechanismList",
"(",
"s",
".",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"result",
":=",
"make",
"(",
"[",
"]",
"Mechanism",
",",
"len",
"(",
"list",
")",
")",
"\n",
"for",
"i",
",",
"mech",
":=",
"range",
"list",
"{",
"result",
"[",
"i",
"]",
"=",
"Mechanism",
"{",
"mechanism",
":",
"mech",
",",
"slot",
":",
"s",
",",
"}",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
]
| // Mechanisms returns a list of Mechanisms available on the token in this
// slot. | [
"Mechanisms",
"returns",
"a",
"list",
"of",
"Mechanisms",
"available",
"on",
"the",
"token",
"in",
"this",
"slot",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/p11/slot.go#L50-L63 |
11,543 | miekg/pkcs11 | p11/slot.go | Info | func (m *Mechanism) Info() (pkcs11.MechanismInfo, error) {
return m.slot.ctx.GetMechanismInfo(m.slot.id, []*pkcs11.Mechanism{m.mechanism})
} | go | func (m *Mechanism) Info() (pkcs11.MechanismInfo, error) {
return m.slot.ctx.GetMechanismInfo(m.slot.id, []*pkcs11.Mechanism{m.mechanism})
} | [
"func",
"(",
"m",
"*",
"Mechanism",
")",
"Info",
"(",
")",
"(",
"pkcs11",
".",
"MechanismInfo",
",",
"error",
")",
"{",
"return",
"m",
".",
"slot",
".",
"ctx",
".",
"GetMechanismInfo",
"(",
"m",
".",
"slot",
".",
"id",
",",
"[",
"]",
"*",
"pkcs11",
".",
"Mechanism",
"{",
"m",
".",
"mechanism",
"}",
")",
"\n",
"}"
]
| // Info returns information about this mechanism. | [
"Info",
"returns",
"information",
"about",
"this",
"mechanism",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/p11/slot.go#L92-L94 |
11,544 | miekg/pkcs11 | p11/crypto.go | Sign | 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 | 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
} | [
"func",
"(",
"priv",
"PrivateKey",
")",
"Sign",
"(",
"mechanism",
"pkcs11",
".",
"Mechanism",
",",
"message",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"s",
":=",
"priv",
".",
"session",
"\n",
"s",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"Unlock",
"(",
")",
"\n",
"err",
":=",
"s",
".",
"ctx",
".",
"SignInit",
"(",
"s",
".",
"handle",
",",
"[",
"]",
"*",
"pkcs11",
".",
"Mechanism",
"{",
"&",
"mechanism",
"}",
",",
"priv",
".",
"objectHandle",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"out",
",",
"err",
":=",
"s",
".",
"ctx",
".",
"Sign",
"(",
"s",
".",
"handle",
",",
"message",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"out",
",",
"nil",
"\n",
"}"
]
| // Sign signs the input with a given mechanism. | [
"Sign",
"signs",
"the",
"input",
"with",
"a",
"given",
"mechanism",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/p11/crypto.go#L34-L47 |
11,545 | miekg/pkcs11 | p11/crypto.go | Verify | 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 | 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
} | [
"func",
"(",
"pub",
"PublicKey",
")",
"Verify",
"(",
"mechanism",
"pkcs11",
".",
"Mechanism",
",",
"message",
",",
"signature",
"[",
"]",
"byte",
")",
"error",
"{",
"s",
":=",
"pub",
".",
"session",
"\n",
"s",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"Unlock",
"(",
")",
"\n",
"err",
":=",
"s",
".",
"ctx",
".",
"VerifyInit",
"(",
"s",
".",
"handle",
",",
"[",
"]",
"*",
"pkcs11",
".",
"Mechanism",
"{",
"&",
"mechanism",
"}",
",",
"pub",
".",
"objectHandle",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"s",
".",
"ctx",
".",
"Verify",
"(",
"s",
".",
"handle",
",",
"message",
",",
"signature",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Verify verifies a signature over a message with a given mechanism. | [
"Verify",
"verifies",
"a",
"signature",
"over",
"a",
"message",
"with",
"a",
"given",
"mechanism",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/p11/crypto.go#L50-L63 |
11,546 | miekg/pkcs11 | p11/crypto.go | Encrypt | 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 | 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
} | [
"func",
"(",
"pub",
"PublicKey",
")",
"Encrypt",
"(",
"mechanism",
"pkcs11",
".",
"Mechanism",
",",
"plaintext",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"s",
":=",
"pub",
".",
"session",
"\n",
"s",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"Unlock",
"(",
")",
"\n",
"err",
":=",
"s",
".",
"ctx",
".",
"EncryptInit",
"(",
"s",
".",
"handle",
",",
"[",
"]",
"*",
"pkcs11",
".",
"Mechanism",
"{",
"&",
"mechanism",
"}",
",",
"pub",
".",
"objectHandle",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"out",
",",
"err",
":=",
"s",
".",
"ctx",
".",
"Encrypt",
"(",
"s",
".",
"handle",
",",
"plaintext",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"out",
",",
"nil",
"\n",
"}"
]
| // Encrypt encrypts a plaintext with a given mechanism. | [
"Encrypt",
"encrypts",
"a",
"plaintext",
"with",
"a",
"given",
"mechanism",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/p11/crypto.go#L66-L79 |
11,547 | miekg/pkcs11 | types.go | cBBool | func cBBool(x bool) C.CK_BBOOL {
if x {
return C.CK_BBOOL(C.CK_TRUE)
}
return C.CK_BBOOL(C.CK_FALSE)
} | go | func cBBool(x bool) C.CK_BBOOL {
if x {
return C.CK_BBOOL(C.CK_TRUE)
}
return C.CK_BBOOL(C.CK_FALSE)
} | [
"func",
"cBBool",
"(",
"x",
"bool",
")",
"C",
".",
"CK_BBOOL",
"{",
"if",
"x",
"{",
"return",
"C",
".",
"CK_BBOOL",
"(",
"C",
".",
"CK_TRUE",
")",
"\n",
"}",
"\n",
"return",
"C",
".",
"CK_BBOOL",
"(",
"C",
".",
"CK_FALSE",
")",
"\n",
"}"
]
| // cBBool converts a bool to a CK_BBOOL. | [
"cBBool",
"converts",
"a",
"bool",
"to",
"a",
"CK_BBOOL",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/types.go#L61-L66 |
11,548 | miekg/pkcs11 | types.go | NewAttribute | 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 | 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
} | [
"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",
")",
"\n",
"a",
".",
"Type",
"=",
"typ",
"\n",
"if",
"x",
"==",
"nil",
"{",
"return",
"a",
"\n",
"}",
"\n",
"switch",
"v",
":=",
"x",
".",
"(",
"type",
")",
"{",
"case",
"bool",
":",
"if",
"v",
"{",
"a",
".",
"Value",
"=",
"[",
"]",
"byte",
"{",
"1",
"}",
"\n",
"}",
"else",
"{",
"a",
".",
"Value",
"=",
"[",
"]",
"byte",
"{",
"0",
"}",
"\n",
"}",
"\n",
"case",
"int",
":",
"a",
".",
"Value",
"=",
"uintToBytes",
"(",
"uint64",
"(",
"v",
")",
")",
"\n",
"case",
"uint",
":",
"a",
".",
"Value",
"=",
"uintToBytes",
"(",
"uint64",
"(",
"v",
")",
")",
"\n",
"case",
"string",
":",
"a",
".",
"Value",
"=",
"[",
"]",
"byte",
"(",
"v",
")",
"\n",
"case",
"[",
"]",
"byte",
":",
"a",
".",
"Value",
"=",
"v",
"\n",
"case",
"time",
".",
"Time",
":",
"// for CKA_DATE",
"a",
".",
"Value",
"=",
"cDate",
"(",
"v",
")",
"\n",
"default",
":",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"a",
"\n",
"}"
]
| // NewAttribute allocates a Attribute and returns a pointer to it.
// Note that this is merely a convenience function, as values returned
// from the HSM are not converted back to Go values, those are just raw
// byte slices. | [
"NewAttribute",
"allocates",
"a",
"Attribute",
"and",
"returns",
"a",
"pointer",
"to",
"it",
".",
"Note",
"that",
"this",
"is",
"merely",
"a",
"convenience",
"function",
"as",
"values",
"returned",
"from",
"the",
"HSM",
"are",
"not",
"converted",
"back",
"to",
"Go",
"values",
"those",
"are",
"just",
"raw",
"byte",
"slices",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/types.go#L167-L197 |
11,549 | miekg/pkcs11 | types.go | cAttributeList | 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 | 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))
} | [
"func",
"cAttributeList",
"(",
"a",
"[",
"]",
"*",
"Attribute",
")",
"(",
"arena",
",",
"C",
".",
"CK_ATTRIBUTE_PTR",
",",
"C",
".",
"CK_ULONG",
")",
"{",
"var",
"arena",
"arena",
"\n",
"if",
"len",
"(",
"a",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
",",
"0",
"\n",
"}",
"\n",
"pa",
":=",
"make",
"(",
"[",
"]",
"C",
".",
"CK_ATTRIBUTE",
",",
"len",
"(",
"a",
")",
")",
"\n",
"for",
"i",
",",
"attr",
":=",
"range",
"a",
"{",
"pa",
"[",
"i",
"]",
".",
"_type",
"=",
"C",
".",
"CK_ATTRIBUTE_TYPE",
"(",
"attr",
".",
"Type",
")",
"\n",
"if",
"len",
"(",
"attr",
".",
"Value",
")",
"!=",
"0",
"{",
"buf",
",",
"len",
":=",
"arena",
".",
"Allocate",
"(",
"attr",
".",
"Value",
")",
"\n",
"// field is unaligned on windows so this has to call into C",
"C",
".",
"putAttributePval",
"(",
"&",
"pa",
"[",
"i",
"]",
",",
"buf",
")",
"\n",
"pa",
"[",
"i",
"]",
".",
"ulValueLen",
"=",
"len",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"arena",
",",
"&",
"pa",
"[",
"0",
"]",
",",
"C",
".",
"CK_ULONG",
"(",
"len",
"(",
"a",
")",
")",
"\n",
"}"
]
| // cAttribute returns the start address and the length of an attribute list. | [
"cAttribute",
"returns",
"the",
"start",
"address",
"and",
"the",
"length",
"of",
"an",
"attribute",
"list",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/types.go#L200-L216 |
11,550 | miekg/pkcs11 | types.go | NewMechanism | 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 | 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
} | [
"func",
"NewMechanism",
"(",
"mech",
"uint",
",",
"x",
"interface",
"{",
"}",
")",
"*",
"Mechanism",
"{",
"m",
":=",
"new",
"(",
"Mechanism",
")",
"\n",
"m",
".",
"Mechanism",
"=",
"mech",
"\n",
"if",
"x",
"==",
"nil",
"{",
"return",
"m",
"\n",
"}",
"\n\n",
"switch",
"p",
":=",
"x",
".",
"(",
"type",
")",
"{",
"case",
"*",
"GCMParams",
",",
"*",
"OAEPParams",
",",
"*",
"ECDH1DeriveParams",
":",
"// contains pointers; defer serialization until cMechanism",
"m",
".",
"generator",
"=",
"p",
"\n",
"case",
"[",
"]",
"byte",
":",
"m",
".",
"Parameter",
"=",
"p",
"\n",
"default",
":",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"m",
"\n",
"}"
]
| // NewMechanism returns a pointer to an initialized Mechanism. | [
"NewMechanism",
"returns",
"a",
"pointer",
"to",
"an",
"initialized",
"Mechanism",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/types.go#L238-L256 |
11,551 | miekg/pkcs11 | p11/object.go | Label | func (o Object) Label() (string, error) {
labelBytes, err := o.Attribute(pkcs11.CKA_LABEL)
if err != nil {
return "", err
}
return string(labelBytes), nil
} | go | func (o Object) Label() (string, error) {
labelBytes, err := o.Attribute(pkcs11.CKA_LABEL)
if err != nil {
return "", err
}
return string(labelBytes), nil
} | [
"func",
"(",
"o",
"Object",
")",
"Label",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"labelBytes",
",",
"err",
":=",
"o",
".",
"Attribute",
"(",
"pkcs11",
".",
"CKA_LABEL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"string",
"(",
"labelBytes",
")",
",",
"nil",
"\n",
"}"
]
| // Label returns the label of an object. | [
"Label",
"returns",
"the",
"label",
"of",
"an",
"object",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/p11/object.go#L19-L25 |
11,552 | miekg/pkcs11 | p11/object.go | Set | 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 | 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
} | [
"func",
"(",
"o",
"Object",
")",
"Set",
"(",
"attributeType",
"uint",
",",
"value",
"[",
"]",
"byte",
")",
"error",
"{",
"o",
".",
"session",
".",
"Lock",
"(",
")",
"\n",
"defer",
"o",
".",
"session",
".",
"Unlock",
"(",
")",
"\n\n",
"err",
":=",
"o",
".",
"session",
".",
"ctx",
".",
"SetAttributeValue",
"(",
"o",
".",
"session",
".",
"handle",
",",
"o",
".",
"objectHandle",
",",
"[",
"]",
"*",
"pkcs11",
".",
"Attribute",
"{",
"pkcs11",
".",
"NewAttribute",
"(",
"attributeType",
",",
"value",
")",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Set sets exactly one attribute on this object. | [
"Set",
"sets",
"exactly",
"one",
"attribute",
"on",
"this",
"object",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/p11/object.go#L62-L72 |
11,553 | miekg/pkcs11 | p11/object.go | Copy | 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 | 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
} | [
"func",
"(",
"o",
"Object",
")",
"Copy",
"(",
"template",
"[",
"]",
"*",
"pkcs11",
".",
"Attribute",
")",
"(",
"Object",
",",
"error",
")",
"{",
"s",
":=",
"o",
".",
"session",
"\n",
"s",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"Unlock",
"(",
")",
"\n",
"newHandle",
",",
"err",
":=",
"s",
".",
"ctx",
".",
"CopyObject",
"(",
"s",
".",
"handle",
",",
"o",
".",
"objectHandle",
",",
"template",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Object",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"Object",
"{",
"session",
":",
"s",
",",
"objectHandle",
":",
"newHandle",
",",
"}",
",",
"nil",
"\n",
"}"
]
| // Copy makes a copy of this object, with the attributes in template applied on
// top of it, if possible. | [
"Copy",
"makes",
"a",
"copy",
"of",
"this",
"object",
"with",
"the",
"attributes",
"in",
"template",
"applied",
"on",
"top",
"of",
"it",
"if",
"possible",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/p11/object.go#L76-L88 |
11,554 | miekg/pkcs11 | p11/object.go | Destroy | func (o Object) Destroy() error {
s := o.session
s.Lock()
defer s.Unlock()
return s.ctx.DestroyObject(s.handle, o.objectHandle)
} | go | func (o Object) Destroy() error {
s := o.session
s.Lock()
defer s.Unlock()
return s.ctx.DestroyObject(s.handle, o.objectHandle)
} | [
"func",
"(",
"o",
"Object",
")",
"Destroy",
"(",
")",
"error",
"{",
"s",
":=",
"o",
".",
"session",
"\n",
"s",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"Unlock",
"(",
")",
"\n",
"return",
"s",
".",
"ctx",
".",
"DestroyObject",
"(",
"s",
".",
"handle",
",",
"o",
".",
"objectHandle",
")",
"\n",
"}"
]
| // Destroy destroys this object. | [
"Destroy",
"destroys",
"this",
"object",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/p11/object.go#L91-L96 |
11,555 | miekg/pkcs11 | p11/module.go | Slots | 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 | 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
} | [
"func",
"(",
"m",
"Module",
")",
"Slots",
"(",
")",
"(",
"[",
"]",
"Slot",
",",
"error",
")",
"{",
"ids",
",",
"err",
":=",
"m",
".",
"ctx",
".",
"GetSlotList",
"(",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"result",
":=",
"make",
"(",
"[",
"]",
"Slot",
",",
"len",
"(",
"ids",
")",
")",
"\n",
"for",
"i",
",",
"id",
":=",
"range",
"ids",
"{",
"result",
"[",
"i",
"]",
"=",
"Slot",
"{",
"ctx",
":",
"m",
".",
"ctx",
",",
"id",
":",
"id",
",",
"}",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
]
| // Slots returns all available Slots that have a token present. | [
"Slots",
"returns",
"all",
"available",
"Slots",
"that",
"have",
"a",
"token",
"present",
"."
]
| a667d056470f6e0da7facaff2466f0d2645e35d7 | https://github.com/miekg/pkcs11/blob/a667d056470f6e0da7facaff2466f0d2645e35d7/p11/module.go#L112-L125 |
11,556 | jacobsa/fuse | fuseutil/dirent.go | WriteDirent | 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 | 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
} | [
"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",
"\n",
"off",
"uint64",
"\n",
"namelen",
"uint32",
"\n",
"type_",
"uint32",
"\n",
"name",
"[",
"0",
"]",
"byte",
"\n",
"}",
"\n\n",
"const",
"direntAlignment",
"=",
"8",
"\n",
"const",
"direntSize",
"=",
"8",
"+",
"8",
"+",
"4",
"+",
"4",
"\n\n",
"// Compute the number of bytes of padding we'll need to maintain alignment",
"// for the next entry.",
"var",
"padLen",
"int",
"\n",
"if",
"len",
"(",
"d",
".",
"Name",
")",
"%",
"direntAlignment",
"!=",
"0",
"{",
"padLen",
"=",
"direntAlignment",
"-",
"(",
"len",
"(",
"d",
".",
"Name",
")",
"%",
"direntAlignment",
")",
"\n",
"}",
"\n\n",
"// Do we have enough room?",
"totalLen",
":=",
"direntSize",
"+",
"len",
"(",
"d",
".",
"Name",
")",
"+",
"padLen",
"\n",
"if",
"totalLen",
">",
"len",
"(",
"buf",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"// Write the header.",
"de",
":=",
"fuse_dirent",
"{",
"ino",
":",
"uint64",
"(",
"d",
".",
"Inode",
")",
",",
"off",
":",
"uint64",
"(",
"d",
".",
"Offset",
")",
",",
"namelen",
":",
"uint32",
"(",
"len",
"(",
"d",
".",
"Name",
")",
")",
",",
"type_",
":",
"uint32",
"(",
"d",
".",
"Type",
")",
",",
"}",
"\n\n",
"n",
"+=",
"copy",
"(",
"buf",
"[",
"n",
":",
"]",
",",
"(",
"*",
"[",
"direntSize",
"]",
"byte",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"de",
")",
")",
"[",
":",
"]",
")",
"\n\n",
"// Write the name afterward.",
"n",
"+=",
"copy",
"(",
"buf",
"[",
"n",
":",
"]",
",",
"d",
".",
"Name",
")",
"\n\n",
"// Add any necessary padding.",
"if",
"padLen",
"!=",
"0",
"{",
"var",
"padding",
"[",
"direntAlignment",
"]",
"byte",
"\n",
"n",
"+=",
"copy",
"(",
"buf",
"[",
"n",
":",
"]",
",",
"padding",
"[",
":",
"padLen",
"]",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
]
| // Write the supplied directory entry intto the given buffer in the format
// expected in fuseops.ReadFileOp.Data, returning the number of bytes written.
// Return zero if the entry would not fit. | [
"Write",
"the",
"supplied",
"directory",
"entry",
"intto",
"the",
"given",
"buffer",
"in",
"the",
"format",
"expected",
"in",
"fuseops",
".",
"ReadFileOp",
".",
"Data",
"returning",
"the",
"number",
"of",
"bytes",
"written",
".",
"Return",
"zero",
"if",
"the",
"entry",
"would",
"not",
"fit",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/fuseutil/dirent.go#L56-L105 |
11,557 | jacobsa/fuse | conversions.go | convertExpirationTime | 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 | 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
} | [
"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",
"(",
")",
")",
"\n",
"if",
"d",
">",
"0",
"{",
"secs",
"=",
"uint64",
"(",
"d",
"/",
"time",
".",
"Second",
")",
"\n",
"nsecs",
"=",
"uint32",
"(",
"(",
"d",
"%",
"time",
".",
"Second",
")",
"/",
"time",
".",
"Nanosecond",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
]
| // Convert an absolute cache expiration time to a relative time from now for
// consumption by the fuse kernel module. | [
"Convert",
"an",
"absolute",
"cache",
"expiration",
"time",
"to",
"a",
"relative",
"time",
"from",
"now",
"for",
"consumption",
"by",
"the",
"fuse",
"kernel",
"module",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/conversions.go#L863-L875 |
11,558 | jacobsa/fuse | samples/memfs/inode.go | SetAttributes | 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 | 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
}
} | [
"func",
"(",
"in",
"*",
"inode",
")",
"SetAttributes",
"(",
"size",
"*",
"uint64",
",",
"mode",
"*",
"os",
".",
"FileMode",
",",
"mtime",
"*",
"time",
".",
"Time",
")",
"{",
"// Update the modification time.",
"in",
".",
"attrs",
".",
"Mtime",
"=",
"time",
".",
"Now",
"(",
")",
"\n\n",
"// Truncate?",
"if",
"size",
"!=",
"nil",
"{",
"intSize",
":=",
"int",
"(",
"*",
"size",
")",
"\n\n",
"// Update contents.",
"if",
"intSize",
"<=",
"len",
"(",
"in",
".",
"contents",
")",
"{",
"in",
".",
"contents",
"=",
"in",
".",
"contents",
"[",
":",
"intSize",
"]",
"\n",
"}",
"else",
"{",
"padding",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"intSize",
"-",
"len",
"(",
"in",
".",
"contents",
")",
")",
"\n",
"in",
".",
"contents",
"=",
"append",
"(",
"in",
".",
"contents",
",",
"padding",
"...",
")",
"\n",
"}",
"\n\n",
"// Update attributes.",
"in",
".",
"attrs",
".",
"Size",
"=",
"*",
"size",
"\n",
"}",
"\n\n",
"// Change mode?",
"if",
"mode",
"!=",
"nil",
"{",
"in",
".",
"attrs",
".",
"Mode",
"=",
"*",
"mode",
"\n",
"}",
"\n\n",
"// Change mtime?",
"if",
"mtime",
"!=",
"nil",
"{",
"in",
".",
"attrs",
".",
"Mtime",
"=",
"*",
"mtime",
"\n",
"}",
"\n",
"}"
]
| // Update attributes from non-nil parameters. | [
"Update",
"attributes",
"from",
"non",
"-",
"nil",
"parameters",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/samples/memfs/inode.go#L352-L384 |
11,559 | jacobsa/fuse | connection.go | Init | 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 | 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
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"Init",
"(",
")",
"(",
"err",
"error",
")",
"{",
"// Read the init op.",
"ctx",
",",
"op",
",",
"err",
":=",
"c",
".",
"ReadOp",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"initOp",
",",
"ok",
":=",
"op",
".",
"(",
"*",
"initOp",
")",
"\n",
"if",
"!",
"ok",
"{",
"c",
".",
"Reply",
"(",
"ctx",
",",
"syscall",
".",
"EPROTO",
")",
"\n",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"op",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Make sure the protocol version spoken by the kernel is new enough.",
"min",
":=",
"fusekernel",
".",
"Protocol",
"{",
"fusekernel",
".",
"ProtoVersionMinMajor",
",",
"fusekernel",
".",
"ProtoVersionMinMinor",
",",
"}",
"\n\n",
"if",
"initOp",
".",
"Kernel",
".",
"LT",
"(",
"min",
")",
"{",
"c",
".",
"Reply",
"(",
"ctx",
",",
"syscall",
".",
"EPROTO",
")",
"\n",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"initOp",
".",
"Kernel",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Downgrade our protocol if necessary.",
"c",
".",
"protocol",
"=",
"fusekernel",
".",
"Protocol",
"{",
"fusekernel",
".",
"ProtoVersionMaxMajor",
",",
"fusekernel",
".",
"ProtoVersionMaxMinor",
",",
"}",
"\n\n",
"if",
"initOp",
".",
"Kernel",
".",
"LT",
"(",
"c",
".",
"protocol",
")",
"{",
"c",
".",
"protocol",
"=",
"initOp",
".",
"Kernel",
"\n",
"}",
"\n\n",
"// Respond to the init op.",
"initOp",
".",
"Library",
"=",
"c",
".",
"protocol",
"\n",
"initOp",
".",
"MaxReadahead",
"=",
"maxReadahead",
"\n",
"initOp",
".",
"MaxWrite",
"=",
"buffer",
".",
"MaxWriteSize",
"\n\n",
"initOp",
".",
"Flags",
"=",
"0",
"\n\n",
"// Tell the kernel not to use pitifully small 4 KiB writes.",
"initOp",
".",
"Flags",
"|=",
"fusekernel",
".",
"InitBigWrites",
"\n\n",
"// Enable writeback caching if the user hasn't asked us not to.",
"if",
"!",
"c",
".",
"cfg",
".",
"DisableWritebackCaching",
"{",
"initOp",
".",
"Flags",
"|=",
"fusekernel",
".",
"InitWritebackCache",
"\n",
"}",
"\n\n",
"c",
".",
"Reply",
"(",
"ctx",
",",
"nil",
")",
"\n",
"return",
"\n",
"}"
]
| // Init performs the work necessary to cause the mount process to complete. | [
"Init",
"performs",
"the",
"work",
"necessary",
"to",
"cause",
"the",
"mount",
"process",
"to",
"complete",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/connection.go#L119-L173 |
11,560 | jacobsa/fuse | connection.go | readMessage | 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 | 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
}
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"readMessage",
"(",
")",
"(",
"m",
"*",
"buffer",
".",
"InMessage",
",",
"err",
"error",
")",
"{",
"// Allocate a message.",
"m",
"=",
"c",
".",
"getInMessage",
"(",
")",
"\n\n",
"// Loop past transient errors.",
"for",
"{",
"// Attempt a reaed.",
"err",
"=",
"m",
".",
"Init",
"(",
"c",
".",
"dev",
")",
"\n\n",
"// 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",
"\n\n",
"case",
"syscall",
".",
"EINTR",
":",
"err",
"=",
"nil",
"\n",
"continue",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"c",
".",
"putInMessage",
"(",
"m",
")",
"\n",
"m",
"=",
"nil",
"\n",
"return",
"\n",
"}",
"\n\n",
"return",
"\n",
"}",
"\n",
"}"
]
| // Read the next message from the kernel. The message must later be destroyed
// using destroyInMessage. | [
"Read",
"the",
"next",
"message",
"from",
"the",
"kernel",
".",
"The",
"message",
"must",
"later",
"be",
"destroyed",
"using",
"destroyInMessage",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/connection.go#L310-L345 |
11,561 | jacobsa/fuse | connection.go | writeMessage | 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 | 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
} | [
"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",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"n",
"!=",
"len",
"(",
"msg",
")",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"n",
",",
"len",
"(",
"msg",
")",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
]
| // Write the supplied message to the kernel. | [
"Write",
"the",
"supplied",
"message",
"to",
"the",
"kernel",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/connection.go#L348-L361 |
11,562 | jacobsa/fuse | connection.go | shouldLogError | 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 | 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
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"shouldLogError",
"(",
"op",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"bool",
"{",
"// We don't log non-errors.",
"if",
"err",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// We can't log if there's nothing to log to.",
"if",
"c",
".",
"errorLogger",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"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",
"\n",
"}",
"\n\n",
"case",
"*",
"fuseops",
".",
"GetXattrOp",
":",
"if",
"err",
"==",
"syscall",
".",
"ENODATA",
"||",
"err",
"==",
"syscall",
".",
"ERANGE",
"{",
"return",
"false",
"\n",
"}",
"\n",
"case",
"*",
"unknownOp",
":",
"// Don't bother the user with methods we intentionally don't support.",
"if",
"err",
"==",
"syscall",
".",
"ENOSYS",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
]
| // Skip errors that happen as a matter of course, since they spook users. | [
"Skip",
"errors",
"that",
"happen",
"as",
"a",
"matter",
"of",
"course",
"since",
"they",
"spook",
"users",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/connection.go#L414-L448 |
11,563 | jacobsa/fuse | internal/buffer/out_message.go | init | 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 | 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)
}
} | [
"func",
"init",
"(",
")",
"{",
"a",
":=",
"unsafe",
".",
"Offsetof",
"(",
"OutMessage",
"{",
"}",
".",
"header",
")",
"+",
"uintptr",
"(",
"OutMessageHeaderSize",
")",
"\n",
"b",
":=",
"unsafe",
".",
"Offsetof",
"(",
"OutMessage",
"{",
"}",
".",
"payload",
")",
"\n\n",
"if",
"a",
"!=",
"b",
"{",
"log",
".",
"Panicf",
"(",
"\"",
"\"",
",",
"a",
",",
"b",
")",
"\n",
"}",
"\n",
"}"
]
| // Make sure that the header and payload are contiguous. | [
"Make",
"sure",
"that",
"the",
"header",
"and",
"payload",
"are",
"contiguous",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/internal/buffer/out_message.go#L44-L53 |
11,564 | jacobsa/fuse | internal/buffer/out_message.go | Reset | 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 | 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
} | [
"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",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"a",
":=",
"(",
"*",
"[",
"3",
"]",
"uint64",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"m",
")",
")",
"\n",
"a",
"[",
"0",
"]",
"=",
"0",
"\n",
"a",
"[",
"1",
"]",
"=",
"0",
"\n",
"a",
"[",
"2",
"]",
"=",
"0",
"\n",
"}"
]
| // Reset resets m so that it's ready to be used again. Afterward, the contents
// are solely a zeroed fusekernel.OutHeader struct. | [
"Reset",
"resets",
"m",
"so",
"that",
"it",
"s",
"ready",
"to",
"be",
"used",
"again",
".",
"Afterward",
"the",
"contents",
"are",
"solely",
"a",
"zeroed",
"fusekernel",
".",
"OutHeader",
"struct",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/internal/buffer/out_message.go#L57-L74 |
11,565 | jacobsa/fuse | internal/buffer/out_message.go | Grow | func (m *OutMessage) Grow(n int) (p unsafe.Pointer) {
p = m.GrowNoZero(n)
if p != nil {
memclr(p, uintptr(n))
}
return
} | go | func (m *OutMessage) Grow(n int) (p unsafe.Pointer) {
p = m.GrowNoZero(n)
if p != nil {
memclr(p, uintptr(n))
}
return
} | [
"func",
"(",
"m",
"*",
"OutMessage",
")",
"Grow",
"(",
"n",
"int",
")",
"(",
"p",
"unsafe",
".",
"Pointer",
")",
"{",
"p",
"=",
"m",
".",
"GrowNoZero",
"(",
"n",
")",
"\n",
"if",
"p",
"!=",
"nil",
"{",
"memclr",
"(",
"p",
",",
"uintptr",
"(",
"n",
")",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
]
| // Grow grows m's buffer by the given number of bytes, returning a pointer to
// the start of the new segment, which is guaranteed to be zeroed. If there is
// insufficient space, it returns nil. | [
"Grow",
"grows",
"m",
"s",
"buffer",
"by",
"the",
"given",
"number",
"of",
"bytes",
"returning",
"a",
"pointer",
"to",
"the",
"start",
"of",
"the",
"new",
"segment",
"which",
"is",
"guaranteed",
"to",
"be",
"zeroed",
".",
"If",
"there",
"is",
"insufficient",
"space",
"it",
"returns",
"nil",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/internal/buffer/out_message.go#L84-L91 |
11,566 | jacobsa/fuse | internal/buffer/out_message.go | GrowNoZero | 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 | 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
} | [
"func",
"(",
"m",
"*",
"OutMessage",
")",
"GrowNoZero",
"(",
"n",
"int",
")",
"(",
"p",
"unsafe",
".",
"Pointer",
")",
"{",
"// Will we overflow the buffer?",
"o",
":=",
"m",
".",
"payloadOffset",
"\n",
"if",
"len",
"(",
"m",
".",
"payload",
")",
"-",
"o",
"<",
"n",
"{",
"return",
"\n",
"}",
"\n\n",
"p",
"=",
"unsafe",
".",
"Pointer",
"(",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"m",
".",
"payload",
")",
")",
"+",
"uintptr",
"(",
"o",
")",
")",
"\n",
"m",
".",
"payloadOffset",
"=",
"o",
"+",
"n",
"\n\n",
"return",
"\n",
"}"
]
| // GrowNoZero is equivalent to Grow, except the new segment is not zeroed. Use
// with caution! | [
"GrowNoZero",
"is",
"equivalent",
"to",
"Grow",
"except",
"the",
"new",
"segment",
"is",
"not",
"zeroed",
".",
"Use",
"with",
"caution!"
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/internal/buffer/out_message.go#L95-L106 |
11,567 | jacobsa/fuse | internal/buffer/out_message.go | AppendString | 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 | 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
} | [
"func",
"(",
"m",
"*",
"OutMessage",
")",
"AppendString",
"(",
"src",
"string",
")",
"{",
"p",
":=",
"m",
".",
"GrowNoZero",
"(",
"len",
"(",
"src",
")",
")",
"\n",
"if",
"p",
"==",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"len",
"(",
"src",
")",
")",
")",
"\n",
"}",
"\n\n",
"sh",
":=",
"(",
"*",
"reflect",
".",
"StringHeader",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"src",
")",
")",
"\n",
"memmove",
"(",
"p",
",",
"unsafe",
".",
"Pointer",
"(",
"sh",
".",
"Data",
")",
",",
"uintptr",
"(",
"sh",
".",
"Len",
")",
")",
"\n\n",
"return",
"\n",
"}"
]
| // AppendString is like Append, but accepts string input. | [
"AppendString",
"is",
"like",
"Append",
"but",
"accepts",
"string",
"input",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/internal/buffer/out_message.go#L136-L146 |
11,568 | jacobsa/fuse | internal/buffer/out_message.go | Bytes | 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 | 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))
} | [
"func",
"(",
"m",
"*",
"OutMessage",
")",
"Bytes",
"(",
")",
"[",
"]",
"byte",
"{",
"l",
":=",
"m",
".",
"Len",
"(",
")",
"\n",
"sh",
":=",
"reflect",
".",
"SliceHeader",
"{",
"Data",
":",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"m",
".",
"header",
")",
")",
",",
"Len",
":",
"l",
",",
"Cap",
":",
"l",
",",
"}",
"\n\n",
"return",
"*",
"(",
"*",
"[",
"]",
"byte",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"sh",
")",
")",
"\n",
"}"
]
| // Bytes returns a reference to the current contents of the buffer, including
// the leading header. | [
"Bytes",
"returns",
"a",
"reference",
"to",
"the",
"current",
"contents",
"of",
"the",
"buffer",
"including",
"the",
"leading",
"header",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/internal/buffer/out_message.go#L155-L164 |
11,569 | jacobsa/fuse | internal/buffer/in_message.go | Init | 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 | 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
} | [
"func",
"(",
"m",
"*",
"InMessage",
")",
"Init",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"err",
"error",
")",
"{",
"n",
",",
"err",
":=",
"r",
".",
"Read",
"(",
"m",
".",
"storage",
"[",
":",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"// Make sure the message is long enough.",
"const",
"headerSize",
"=",
"unsafe",
".",
"Sizeof",
"(",
"fusekernel",
".",
"InHeader",
"{",
"}",
")",
"\n",
"if",
"uintptr",
"(",
"n",
")",
"<",
"headerSize",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"n",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"m",
".",
"remaining",
"=",
"m",
".",
"storage",
"[",
"headerSize",
":",
"n",
"]",
"\n\n",
"// Check the header's length.",
"if",
"int",
"(",
"m",
".",
"Header",
"(",
")",
".",
"Len",
")",
"!=",
"n",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"m",
".",
"Header",
"(",
")",
".",
"Len",
",",
"n",
")",
"\n\n",
"return",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
]
| // Initialize with the data read by a single call to r.Read. The first call to
// Consume will consume the bytes directly after the fusekernel.InHeader
// struct. | [
"Initialize",
"with",
"the",
"data",
"read",
"by",
"a",
"single",
"call",
"to",
"r",
".",
"Read",
".",
"The",
"first",
"call",
"to",
"Consume",
"will",
"consume",
"the",
"bytes",
"directly",
"after",
"the",
"fusekernel",
".",
"InHeader",
"struct",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/internal/buffer/in_message.go#L52-L78 |
11,570 | jacobsa/fuse | internal/buffer/in_message.go | Header | func (m *InMessage) Header() (h *fusekernel.InHeader) {
h = (*fusekernel.InHeader)(unsafe.Pointer(&m.storage[0]))
return
} | go | func (m *InMessage) Header() (h *fusekernel.InHeader) {
h = (*fusekernel.InHeader)(unsafe.Pointer(&m.storage[0]))
return
} | [
"func",
"(",
"m",
"*",
"InMessage",
")",
"Header",
"(",
")",
"(",
"h",
"*",
"fusekernel",
".",
"InHeader",
")",
"{",
"h",
"=",
"(",
"*",
"fusekernel",
".",
"InHeader",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"m",
".",
"storage",
"[",
"0",
"]",
")",
")",
"\n",
"return",
"\n",
"}"
]
| // Return a reference to the header read in the most recent call to Init. | [
"Return",
"a",
"reference",
"to",
"the",
"header",
"read",
"in",
"the",
"most",
"recent",
"call",
"to",
"Init",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/internal/buffer/in_message.go#L81-L84 |
11,571 | jacobsa/fuse | internal/buffer/in_message.go | Consume | 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 | 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
} | [
"func",
"(",
"m",
"*",
"InMessage",
")",
"Consume",
"(",
"n",
"uintptr",
")",
"(",
"p",
"unsafe",
".",
"Pointer",
")",
"{",
"if",
"m",
".",
"Len",
"(",
")",
"==",
"0",
"||",
"n",
">",
"m",
".",
"Len",
"(",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"p",
"=",
"unsafe",
".",
"Pointer",
"(",
"&",
"m",
".",
"remaining",
"[",
"0",
"]",
")",
"\n",
"m",
".",
"remaining",
"=",
"m",
".",
"remaining",
"[",
"n",
":",
"]",
"\n\n",
"return",
"\n",
"}"
]
| // Consume the next n bytes from the message, returning a nil pointer if there
// are fewer than n bytes available. | [
"Consume",
"the",
"next",
"n",
"bytes",
"from",
"the",
"message",
"returning",
"a",
"nil",
"pointer",
"if",
"there",
"are",
"fewer",
"than",
"n",
"bytes",
"available",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/internal/buffer/in_message.go#L93-L102 |
11,572 | jacobsa/fuse | internal/buffer/in_message.go | ConsumeBytes | func (m *InMessage) ConsumeBytes(n uintptr) (b []byte) {
if n > m.Len() {
return
}
b = m.remaining[:n]
m.remaining = m.remaining[n:]
return
} | go | func (m *InMessage) ConsumeBytes(n uintptr) (b []byte) {
if n > m.Len() {
return
}
b = m.remaining[:n]
m.remaining = m.remaining[n:]
return
} | [
"func",
"(",
"m",
"*",
"InMessage",
")",
"ConsumeBytes",
"(",
"n",
"uintptr",
")",
"(",
"b",
"[",
"]",
"byte",
")",
"{",
"if",
"n",
">",
"m",
".",
"Len",
"(",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"b",
"=",
"m",
".",
"remaining",
"[",
":",
"n",
"]",
"\n",
"m",
".",
"remaining",
"=",
"m",
".",
"remaining",
"[",
"n",
":",
"]",
"\n\n",
"return",
"\n",
"}"
]
| // Equivalent to Consume, except returns a slice of bytes. The result will be
// nil if Consume would fail. | [
"Equivalent",
"to",
"Consume",
"except",
"returns",
"a",
"slice",
"of",
"bytes",
".",
"The",
"result",
"will",
"be",
"nil",
"if",
"Consume",
"would",
"fail",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/internal/buffer/in_message.go#L106-L115 |
11,573 | jacobsa/fuse | debug.go | opName | 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 | 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")
} | [
"func",
"opName",
"(",
"op",
"interface",
"{",
"}",
")",
"string",
"{",
"// We expect all ops to be pointers.",
"t",
":=",
"reflect",
".",
"TypeOf",
"(",
"op",
")",
".",
"Elem",
"(",
")",
"\n\n",
"// Strip the \"Op\" from \"FooOp\".",
"return",
"strings",
".",
"TrimSuffix",
"(",
"t",
".",
"Name",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"}"
]
| // Decide on the name of the given op. | [
"Decide",
"on",
"the",
"name",
"of",
"the",
"given",
"op",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/debug.go#L26-L32 |
11,574 | jacobsa/fuse | mount.go | Mount | 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 | 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
} | [
"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",
")",
"\n",
"switch",
"{",
"case",
"os",
".",
"IsNotExist",
"(",
"err",
")",
":",
"return",
"\n\n",
"case",
"err",
"!=",
"nil",
":",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n\n",
"case",
"!",
"fi",
".",
"IsDir",
"(",
")",
":",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"dir",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Initialize the struct.",
"mfs",
"=",
"&",
"MountedFileSystem",
"{",
"dir",
":",
"dir",
",",
"joinStatusAvailable",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"}",
"\n\n",
"// Begin the mounting process, which will continue in the background.",
"ready",
":=",
"make",
"(",
"chan",
"error",
",",
"1",
")",
"\n",
"dev",
",",
"err",
":=",
"mount",
"(",
"dir",
",",
"config",
",",
"ready",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Choose a parent context for ops.",
"cfgCopy",
":=",
"*",
"config",
"\n",
"if",
"cfgCopy",
".",
"OpContext",
"==",
"nil",
"{",
"cfgCopy",
".",
"OpContext",
"=",
"context",
".",
"Background",
"(",
")",
"\n",
"}",
"\n\n",
"// Create a Connection object wrapping the device.",
"connection",
",",
"err",
":=",
"newConnection",
"(",
"cfgCopy",
",",
"config",
".",
"DebugLogger",
",",
"config",
".",
"ErrorLogger",
",",
"dev",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Serve the connection in the background. When done, set the join status.",
"go",
"func",
"(",
")",
"{",
"server",
".",
"ServeOps",
"(",
"connection",
")",
"\n",
"mfs",
".",
"joinStatus",
"=",
"connection",
".",
"close",
"(",
")",
"\n",
"close",
"(",
"mfs",
".",
"joinStatusAvailable",
")",
"\n",
"}",
"(",
")",
"\n\n",
"// Wait for the mount process to complete.",
"if",
"err",
"=",
"<-",
"ready",
";",
"err",
"!=",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
]
| // Mount attempts to mount a file system on the given directory, using the
// supplied Server to serve connection requests. It blocks until the file
// system is successfully mounted. | [
"Mount",
"attempts",
"to",
"mount",
"a",
"file",
"system",
"on",
"the",
"given",
"directory",
"using",
"the",
"supplied",
"Server",
"to",
"serve",
"connection",
"requests",
".",
"It",
"blocks",
"until",
"the",
"file",
"system",
"is",
"successfully",
"mounted",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/mount.go#L35-L101 |
11,575 | jacobsa/fuse | mount_config.go | toMap | 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 | 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
} | [
"func",
"(",
"c",
"*",
"MountConfig",
")",
"toMap",
"(",
")",
"(",
"opts",
"map",
"[",
"string",
"]",
"string",
")",
"{",
"isDarwin",
":=",
"runtime",
".",
"GOOS",
"==",
"\"",
"\"",
"\n",
"opts",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n\n",
"// Enable permissions checking in the kernel. See the comments on",
"// InodeAttributes.Mode.",
"opts",
"[",
"\"",
"\"",
"]",
"=",
"\"",
"\"",
"\n\n",
"// 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",
"\n",
"if",
"runtime",
".",
"GOOS",
"==",
"\"",
"\"",
"&&",
"fsname",
"==",
"\"",
"\"",
"{",
"fsname",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"// Special file system name?",
"if",
"fsname",
"!=",
"\"",
"\"",
"{",
"opts",
"[",
"\"",
"\"",
"]",
"=",
"fsname",
"\n",
"}",
"\n\n",
"subtype",
":=",
"c",
".",
"Subtype",
"\n",
"if",
"subtype",
"!=",
"\"",
"\"",
"{",
"opts",
"[",
"\"",
"\"",
"]",
"=",
"subtype",
"\n",
"}",
"\n\n",
"// Read only?",
"if",
"c",
".",
"ReadOnly",
"{",
"opts",
"[",
"\"",
"\"",
"]",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"// Handle OS X options.",
"if",
"isDarwin",
"{",
"if",
"!",
"c",
".",
"EnableVnodeCaching",
"{",
"opts",
"[",
"\"",
"\"",
"]",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"VolumeName",
"!=",
"\"",
"\"",
"{",
"// Cf. https://github.com/osxfuse/osxfuse/wiki/Mount-options#volname",
"opts",
"[",
"\"",
"\"",
"]",
"=",
"c",
".",
"VolumeName",
"\n",
"}",
"\n",
"}",
"\n\n",
"// 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",
"[",
"\"",
"\"",
"]",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"// Last but not least: other user-supplied options.",
"for",
"k",
",",
"v",
":=",
"range",
"c",
".",
"Options",
"{",
"opts",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
]
| // Create a map containing all of the key=value mount options to be given to
// the mount helper. | [
"Create",
"a",
"map",
"containing",
"all",
"of",
"the",
"key",
"=",
"value",
"mount",
"options",
"to",
"be",
"given",
"to",
"the",
"mount",
"helper",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/mount_config.go#L153-L217 |
11,576 | jacobsa/fuse | mount_config.go | toOptionsString | 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 | 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, ",")
} | [
"func",
"(",
"c",
"*",
"MountConfig",
")",
"toOptionsString",
"(",
")",
"string",
"{",
"var",
"components",
"[",
"]",
"string",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"c",
".",
"toMap",
"(",
")",
"{",
"k",
"=",
"escapeOptionsKey",
"(",
"k",
")",
"\n\n",
"component",
":=",
"k",
"\n",
"if",
"v",
"!=",
"\"",
"\"",
"{",
"component",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"k",
",",
"v",
")",
"\n",
"}",
"\n\n",
"components",
"=",
"append",
"(",
"components",
",",
"component",
")",
"\n",
"}",
"\n\n",
"return",
"strings",
".",
"Join",
"(",
"components",
",",
"\"",
"\"",
")",
"\n",
"}"
]
| // Create an options string suitable for passing to the mount helper. | [
"Create",
"an",
"options",
"string",
"suitable",
"for",
"passing",
"to",
"the",
"mount",
"helper",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/mount_config.go#L227-L241 |
11,577 | jacobsa/fuse | internal/freelist/freelist.go | Get | 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 | 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
} | [
"func",
"(",
"fl",
"*",
"Freelist",
")",
"Get",
"(",
")",
"(",
"p",
"unsafe",
".",
"Pointer",
")",
"{",
"l",
":=",
"len",
"(",
"fl",
".",
"list",
")",
"\n",
"if",
"l",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n\n",
"p",
"=",
"fl",
".",
"list",
"[",
"l",
"-",
"1",
"]",
"\n",
"fl",
".",
"list",
"=",
"fl",
".",
"list",
"[",
":",
"l",
"-",
"1",
"]",
"\n\n",
"return",
"\n",
"}"
]
| // Get an element from the freelist, returning nil if empty. | [
"Get",
"an",
"element",
"from",
"the",
"freelist",
"returning",
"nil",
"if",
"empty",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/internal/freelist/freelist.go#L25-L35 |
11,578 | jacobsa/fuse | internal/freelist/freelist.go | Put | func (fl *Freelist) Put(p unsafe.Pointer) {
fl.list = append(fl.list, p)
} | go | func (fl *Freelist) Put(p unsafe.Pointer) {
fl.list = append(fl.list, p)
} | [
"func",
"(",
"fl",
"*",
"Freelist",
")",
"Put",
"(",
"p",
"unsafe",
".",
"Pointer",
")",
"{",
"fl",
".",
"list",
"=",
"append",
"(",
"fl",
".",
"list",
",",
"p",
")",
"\n",
"}"
]
| // Contribute an element back to the freelist. | [
"Contribute",
"an",
"element",
"back",
"to",
"the",
"freelist",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/internal/freelist/freelist.go#L38-L40 |
11,579 | jacobsa/fuse | internal/fusekernel/protocol.go | LT | func (a Protocol) LT(b Protocol) bool {
return a.Major < b.Major ||
(a.Major == b.Major && a.Minor < b.Minor)
} | go | func (a Protocol) LT(b Protocol) bool {
return a.Major < b.Major ||
(a.Major == b.Major && a.Minor < b.Minor)
} | [
"func",
"(",
"a",
"Protocol",
")",
"LT",
"(",
"b",
"Protocol",
")",
"bool",
"{",
"return",
"a",
".",
"Major",
"<",
"b",
".",
"Major",
"||",
"(",
"a",
".",
"Major",
"==",
"b",
".",
"Major",
"&&",
"a",
".",
"Minor",
"<",
"b",
".",
"Minor",
")",
"\n",
"}"
]
| // LT returns whether a is less than b. | [
"LT",
"returns",
"whether",
"a",
"is",
"less",
"than",
"b",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/internal/fusekernel/protocol.go#L18-L21 |
11,580 | jacobsa/fuse | internal/fusekernel/protocol.go | GE | func (a Protocol) GE(b Protocol) bool {
return a.Major > b.Major ||
(a.Major == b.Major && a.Minor >= b.Minor)
} | go | func (a Protocol) GE(b Protocol) bool {
return a.Major > b.Major ||
(a.Major == b.Major && a.Minor >= b.Minor)
} | [
"func",
"(",
"a",
"Protocol",
")",
"GE",
"(",
"b",
"Protocol",
")",
"bool",
"{",
"return",
"a",
".",
"Major",
">",
"b",
".",
"Major",
"||",
"(",
"a",
".",
"Major",
"==",
"b",
".",
"Major",
"&&",
"a",
".",
"Minor",
">=",
"b",
".",
"Minor",
")",
"\n",
"}"
]
| // GE returns whether a is greater than or equal to b. | [
"GE",
"returns",
"whether",
"a",
"is",
"greater",
"than",
"or",
"equal",
"to",
"b",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/internal/fusekernel/protocol.go#L24-L27 |
11,581 | jacobsa/fuse | samples/subprocess.go | SetUp | func (t *SubprocessTest) SetUp(ti *ogletest.TestInfo) {
err := t.initialize(ti.Ctx)
if err != nil {
panic(err)
}
} | go | func (t *SubprocessTest) SetUp(ti *ogletest.TestInfo) {
err := t.initialize(ti.Ctx)
if err != nil {
panic(err)
}
} | [
"func",
"(",
"t",
"*",
"SubprocessTest",
")",
"SetUp",
"(",
"ti",
"*",
"ogletest",
".",
"TestInfo",
")",
"{",
"err",
":=",
"t",
".",
"initialize",
"(",
"ti",
".",
"Ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"}"
]
| // Mount the file system and initialize the other exported fields of the
// struct. Panics on error. | [
"Mount",
"the",
"file",
"system",
"and",
"initialize",
"the",
"other",
"exported",
"fields",
"of",
"the",
"struct",
".",
"Panics",
"on",
"error",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/samples/subprocess.go#L70-L75 |
11,582 | jacobsa/fuse | samples/subprocess.go | getToolContentsImpl | 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 | 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
} | [
"func",
"getToolContentsImpl",
"(",
")",
"(",
"contents",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"// Fast path: has the user set the flag?",
"if",
"*",
"fToolPath",
"!=",
"\"",
"\"",
"{",
"contents",
",",
"err",
"=",
"ioutil",
".",
"ReadFile",
"(",
"*",
"fToolPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"return",
"\n",
"}",
"\n\n",
"// Create a temporary directory into which we will compile the tool.",
"tempDir",
",",
"err",
":=",
"ioutil",
".",
"TempDir",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"toolPath",
":=",
"path",
".",
"Join",
"(",
"tempDir",
",",
"\"",
"\"",
")",
"\n\n",
"// Ensure that we kill the temporary directory when we're finished here.",
"defer",
"os",
".",
"RemoveAll",
"(",
"tempDir",
")",
"\n\n",
"// Run \"go build\".",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"toolPath",
",",
"\"",
"\"",
")",
"\n\n",
"output",
",",
"err",
":=",
"cmd",
".",
"CombinedOutput",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
",",
"string",
"(",
"output",
")",
")",
"\n\n",
"return",
"\n",
"}",
"\n\n",
"// Slurp the tool contents.",
"contents",
",",
"err",
"=",
"ioutil",
".",
"ReadFile",
"(",
"toolPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
]
| // Implementation detail of getToolPath. | [
"Implementation",
"detail",
"of",
"getToolPath",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/samples/subprocess.go#L83-L133 |
11,583 | jacobsa/fuse | samples/subprocess.go | getToolContents | 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 | 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
} | [
"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",
"(",
")",
"\n",
"}",
")",
"\n\n",
"contents",
",",
"err",
"=",
"getToolContents_Contents",
",",
"getToolContents_Err",
"\n",
"return",
"\n",
"}"
]
| // Build the mount_sample tool if it has not yet been built for this process.
// Return its contents. | [
"Build",
"the",
"mount_sample",
"tool",
"if",
"it",
"has",
"not",
"yet",
"been",
"built",
"for",
"this",
"process",
".",
"Return",
"its",
"contents",
"."
]
| cd3959611bcb6bb23d49f1598d98f2bf44476805 | https://github.com/jacobsa/fuse/blob/cd3959611bcb6bb23d49f1598d98f2bf44476805/samples/subprocess.go#L137-L145 |
11,584 | tebeka/go2xunit | lib/lex.go | NewLineScanner | func NewLineScanner(r io.Reader) *LineScanner {
br := bufio.NewReader(r)
ls := &LineScanner{
Reader: br,
}
return ls
} | go | func NewLineScanner(r io.Reader) *LineScanner {
br := bufio.NewReader(r)
ls := &LineScanner{
Reader: br,
}
return ls
} | [
"func",
"NewLineScanner",
"(",
"r",
"io",
".",
"Reader",
")",
"*",
"LineScanner",
"{",
"br",
":=",
"bufio",
".",
"NewReader",
"(",
"r",
")",
"\n",
"ls",
":=",
"&",
"LineScanner",
"{",
"Reader",
":",
"br",
",",
"}",
"\n",
"return",
"ls",
"\n",
"}"
]
| // NewLineScanner creates a new line scanner from r | [
"NewLineScanner",
"creates",
"a",
"new",
"line",
"scanner",
"from",
"r"
]
| a6d2debe0214087450ec59555dd656c9f76ef85e | https://github.com/tebeka/go2xunit/blob/a6d2debe0214087450ec59555dd656c9f76ef85e/lib/lex.go#L71-L77 |
11,585 | tebeka/go2xunit | lib/lex.go | Scan | 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 | 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
} | [
"func",
"(",
"ls",
"*",
"LineScanner",
")",
"Scan",
"(",
")",
"bool",
"{",
"if",
"ls",
".",
"text",
",",
"_",
",",
"ls",
".",
"err",
"=",
"ls",
".",
"Reader",
".",
"ReadLine",
"(",
")",
";",
"ls",
".",
"err",
"!=",
"nil",
"{",
"if",
"ls",
".",
"err",
"==",
"io",
".",
"EOF",
"{",
"ls",
".",
"err",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"ls",
".",
"lnum",
"++",
"\n",
"return",
"true",
"\n",
"}"
]
| // Scan advances to next line. | [
"Scan",
"advances",
"to",
"next",
"line",
"."
]
| a6d2debe0214087450ec59555dd656c9f76ef85e | https://github.com/tebeka/go2xunit/blob/a6d2debe0214087450ec59555dd656c9f76ef85e/lib/lex.go#L80-L89 |
11,586 | tebeka/go2xunit | lib/lex.go | Scan | 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 | 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
} | [
"func",
"(",
"lex",
"*",
"GotestLexer",
")",
"Scan",
"(",
")",
"bool",
"{",
"if",
"!",
"lex",
".",
"scanner",
".",
"Scan",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"lex",
".",
"scanner",
".",
"Err",
"(",
")",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"line",
":=",
"lex",
".",
"scanner",
".",
"Text",
"(",
")",
"\n",
"lnum",
":=",
"lex",
".",
"scanner",
".",
"Line",
"(",
")",
"\n",
"found",
":=",
"false",
"\n",
"for",
"_",
",",
"typ",
":=",
"range",
"gtTypes",
"{",
"if",
"typ",
".",
"re",
".",
"MatchString",
"(",
"line",
")",
"{",
"found",
"=",
"true",
"\n",
"lex",
".",
"tok",
"=",
"&",
"Token",
"{",
"lnum",
",",
"typ",
".",
"typ",
",",
"line",
"}",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"found",
"{",
"lex",
".",
"tok",
"=",
"&",
"Token",
"{",
"lnum",
",",
"DataToken",
",",
"line",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
]
| // Scan scans the next token. Return true if there's a new one | [
"Scan",
"scans",
"the",
"next",
"token",
".",
"Return",
"true",
"if",
"there",
"s",
"a",
"new",
"one"
]
| a6d2debe0214087450ec59555dd656c9f76ef85e | https://github.com/tebeka/go2xunit/blob/a6d2debe0214087450ec59555dd656c9f76ef85e/lib/lex.go#L180-L203 |
11,587 | tebeka/go2xunit | lib/parsers.go | hasDatarace | func hasDatarace(lines []string) bool {
for _, line := range lines {
if matchDatarace(line) {
return true
}
}
return false
} | go | func hasDatarace(lines []string) bool {
for _, line := range lines {
if matchDatarace(line) {
return true
}
}
return false
} | [
"func",
"hasDatarace",
"(",
"lines",
"[",
"]",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"line",
":=",
"range",
"lines",
"{",
"if",
"matchDatarace",
"(",
"line",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
]
| // hasDatarace checks if there's a data race warning in the line | [
"hasDatarace",
"checks",
"if",
"there",
"s",
"a",
"data",
"race",
"warning",
"in",
"the",
"line"
]
| a6d2debe0214087450ec59555dd656c9f76ef85e | https://github.com/tebeka/go2xunit/blob/a6d2debe0214087450ec59555dd656c9f76ef85e/lib/parsers.go#L16-L23 |
11,588 | tebeka/go2xunit | lib/types.go | numStatus | func (suite *Suite) numStatus(status Status) int {
count := 0
for _, test := range suite.Tests {
if test.Status == status {
count++
}
}
return count
} | go | func (suite *Suite) numStatus(status Status) int {
count := 0
for _, test := range suite.Tests {
if test.Status == status {
count++
}
}
return count
} | [
"func",
"(",
"suite",
"*",
"Suite",
")",
"numStatus",
"(",
"status",
"Status",
")",
"int",
"{",
"count",
":=",
"0",
"\n",
"for",
"_",
",",
"test",
":=",
"range",
"suite",
".",
"Tests",
"{",
"if",
"test",
".",
"Status",
"==",
"status",
"{",
"count",
"++",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"count",
"\n",
"}"
]
| // numStatus returns the number of tests in status | [
"numStatus",
"returns",
"the",
"number",
"of",
"tests",
"in",
"status"
]
| a6d2debe0214087450ec59555dd656c9f76ef85e | https://github.com/tebeka/go2xunit/blob/a6d2debe0214087450ec59555dd656c9f76ef85e/lib/types.go#L46-L54 |
11,589 | tebeka/go2xunit | lib/types.go | HasFailures | func (s Suites) HasFailures() bool {
for _, suite := range s {
if suite.NumFailed() > 0 {
return true
}
}
return false
} | go | func (s Suites) HasFailures() bool {
for _, suite := range s {
if suite.NumFailed() > 0 {
return true
}
}
return false
} | [
"func",
"(",
"s",
"Suites",
")",
"HasFailures",
"(",
")",
"bool",
"{",
"for",
"_",
",",
"suite",
":=",
"range",
"s",
"{",
"if",
"suite",
".",
"NumFailed",
"(",
")",
">",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
]
| // HasFailures return true is there's at least one failing suite | [
"HasFailures",
"return",
"true",
"is",
"there",
"s",
"at",
"least",
"one",
"failing",
"suite"
]
| a6d2debe0214087450ec59555dd656c9f76ef85e | https://github.com/tebeka/go2xunit/blob/a6d2debe0214087450ec59555dd656c9f76ef85e/lib/types.go#L65-L72 |
11,590 | tebeka/go2xunit | lib/types.go | Push | func (s *SuiteStack) Push(n *Suite) {
s.nodes = append(s.nodes[:s.count], n)
s.count++
} | go | func (s *SuiteStack) Push(n *Suite) {
s.nodes = append(s.nodes[:s.count], n)
s.count++
} | [
"func",
"(",
"s",
"*",
"SuiteStack",
")",
"Push",
"(",
"n",
"*",
"Suite",
")",
"{",
"s",
".",
"nodes",
"=",
"append",
"(",
"s",
".",
"nodes",
"[",
":",
"s",
".",
"count",
"]",
",",
"n",
")",
"\n",
"s",
".",
"count",
"++",
"\n",
"}"
]
| // Push adds a node to the stack. | [
"Push",
"adds",
"a",
"node",
"to",
"the",
"stack",
"."
]
| a6d2debe0214087450ec59555dd656c9f76ef85e | https://github.com/tebeka/go2xunit/blob/a6d2debe0214087450ec59555dd656c9f76ef85e/lib/types.go#L81-L84 |
11,591 | tebeka/go2xunit | lib/types.go | Pop | func (s *SuiteStack) Pop() *Suite {
if s.count == 0 {
return nil
}
s.count--
return s.nodes[s.count]
} | go | func (s *SuiteStack) Pop() *Suite {
if s.count == 0 {
return nil
}
s.count--
return s.nodes[s.count]
} | [
"func",
"(",
"s",
"*",
"SuiteStack",
")",
"Pop",
"(",
")",
"*",
"Suite",
"{",
"if",
"s",
".",
"count",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"s",
".",
"count",
"--",
"\n",
"return",
"s",
".",
"nodes",
"[",
"s",
".",
"count",
"]",
"\n",
"}"
]
| // Pop removes and returns a node from the stack in last to first order. | [
"Pop",
"removes",
"and",
"returns",
"a",
"node",
"from",
"the",
"stack",
"in",
"last",
"to",
"first",
"order",
"."
]
| a6d2debe0214087450ec59555dd656c9f76ef85e | https://github.com/tebeka/go2xunit/blob/a6d2debe0214087450ec59555dd656c9f76ef85e/lib/types.go#L87-L93 |
11,592 | tebeka/go2xunit | lib/parsers2.go | NewGtParser | func NewGtParser(in io.Reader) Parser {
return &GtParser{
suite: nil,
tests: make(map[string]*Test),
lex: NewGotestLexer(in),
}
} | go | func NewGtParser(in io.Reader) Parser {
return &GtParser{
suite: nil,
tests: make(map[string]*Test),
lex: NewGotestLexer(in),
}
} | [
"func",
"NewGtParser",
"(",
"in",
"io",
".",
"Reader",
")",
"Parser",
"{",
"return",
"&",
"GtParser",
"{",
"suite",
":",
"nil",
",",
"tests",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"Test",
")",
",",
"lex",
":",
"NewGotestLexer",
"(",
"in",
")",
",",
"}",
"\n",
"}"
]
| // NewGtParser return a new gotest parser | [
"NewGtParser",
"return",
"a",
"new",
"gotest",
"parser"
]
| a6d2debe0214087450ec59555dd656c9f76ef85e | https://github.com/tebeka/go2xunit/blob/a6d2debe0214087450ec59555dd656c9f76ef85e/lib/parsers2.go#L35-L41 |
11,593 | tebeka/go2xunit | cmdline.go | validateArgs | 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 | 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
} | [
"func",
"validateArgs",
"(",
")",
"error",
"{",
"if",
"flag",
".",
"NArg",
"(",
")",
">",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"os",
".",
"Args",
"[",
"0",
"]",
")",
"\n",
"}",
"\n\n",
"if",
"args",
".",
"bambooOut",
"&&",
"args",
".",
"xunitnetOut",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // validateArgs validates command line arguments | [
"validateArgs",
"validates",
"command",
"line",
"arguments"
]
| a6d2debe0214087450ec59555dd656c9f76ef85e | https://github.com/tebeka/go2xunit/blob/a6d2debe0214087450ec59555dd656c9f76ef85e/cmdline.go#L41-L51 |
11,594 | tebeka/go2xunit | main.go | getInput | func getInput(filename string) (*os.File, error) {
if filename == "-" || filename == "" {
return os.Stdin, nil
}
return os.Open(filename)
} | go | func getInput(filename string) (*os.File, error) {
if filename == "-" || filename == "" {
return os.Stdin, nil
}
return os.Open(filename)
} | [
"func",
"getInput",
"(",
"filename",
"string",
")",
"(",
"*",
"os",
".",
"File",
",",
"error",
")",
"{",
"if",
"filename",
"==",
"\"",
"\"",
"||",
"filename",
"==",
"\"",
"\"",
"{",
"return",
"os",
".",
"Stdin",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"os",
".",
"Open",
"(",
"filename",
")",
"\n",
"}"
]
| // getInput return input io.File from file name, if file name is - it will
// return os.Stdin | [
"getInput",
"return",
"input",
"io",
".",
"File",
"from",
"file",
"name",
"if",
"file",
"name",
"is",
"-",
"it",
"will",
"return",
"os",
".",
"Stdin"
]
| a6d2debe0214087450ec59555dd656c9f76ef85e | https://github.com/tebeka/go2xunit/blob/a6d2debe0214087450ec59555dd656c9f76ef85e/main.go#L20-L26 |
11,595 | tebeka/go2xunit | main.go | getOutput | func getOutput(filename string) (*os.File, error) {
if filename == "-" || filename == "" {
return os.Stdout, nil
}
return os.Create(filename)
} | go | func getOutput(filename string) (*os.File, error) {
if filename == "-" || filename == "" {
return os.Stdout, nil
}
return os.Create(filename)
} | [
"func",
"getOutput",
"(",
"filename",
"string",
")",
"(",
"*",
"os",
".",
"File",
",",
"error",
")",
"{",
"if",
"filename",
"==",
"\"",
"\"",
"||",
"filename",
"==",
"\"",
"\"",
"{",
"return",
"os",
".",
"Stdout",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"os",
".",
"Create",
"(",
"filename",
")",
"\n",
"}"
]
| // getInput return output io.File from file name, if file name is - it will
// return os.Stdout | [
"getInput",
"return",
"output",
"io",
".",
"File",
"from",
"file",
"name",
"if",
"file",
"name",
"is",
"-",
"it",
"will",
"return",
"os",
".",
"Stdout"
]
| a6d2debe0214087450ec59555dd656c9f76ef85e | https://github.com/tebeka/go2xunit/blob/a6d2debe0214087450ec59555dd656c9f76ef85e/main.go#L30-L36 |
11,596 | tebeka/go2xunit | main.go | getIO | 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 | 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
} | [
"func",
"getIO",
"(",
"inFile",
",",
"outFile",
"string",
")",
"(",
"*",
"os",
".",
"File",
",",
"io",
".",
"Writer",
",",
"error",
")",
"{",
"input",
",",
"err",
":=",
"getInput",
"(",
"inFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"inFile",
",",
"err",
")",
"\n",
"}",
"\n\n",
"output",
",",
"err",
":=",
"getOutput",
"(",
"outFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"outFile",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"input",
",",
"output",
",",
"nil",
"\n",
"}"
]
| // getIO returns input and output streams from file names | [
"getIO",
"returns",
"input",
"and",
"output",
"streams",
"from",
"file",
"names"
]
| a6d2debe0214087450ec59555dd656c9f76ef85e | https://github.com/tebeka/go2xunit/blob/a6d2debe0214087450ec59555dd656c9f76ef85e/main.go#L39-L51 |
11,597 | tebeka/go2xunit | lib/xmlout.go | calcTotals | 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 | 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
} | [
"func",
"(",
"r",
"*",
"TestResults",
")",
"calcTotals",
"(",
")",
"{",
"totalTime",
",",
"_",
":=",
"strconv",
".",
"ParseFloat",
"(",
"r",
".",
"Time",
",",
"64",
")",
"\n",
"for",
"_",
",",
"suite",
":=",
"range",
"r",
".",
"Suites",
"{",
"r",
".",
"NumPassed",
"+=",
"suite",
".",
"NumPassed",
"(",
")",
"\n",
"r",
".",
"NumFailed",
"+=",
"suite",
".",
"NumFailed",
"(",
")",
"\n",
"r",
".",
"NumSkipped",
"+=",
"suite",
".",
"NumSkipped",
"(",
")",
"\n\n",
"suiteTime",
",",
"_",
":=",
"strconv",
".",
"ParseFloat",
"(",
"suite",
".",
"Time",
",",
"64",
")",
"\n",
"totalTime",
"+=",
"suiteTime",
"\n",
"r",
".",
"Time",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"totalTime",
")",
"\n",
"}",
"\n",
"r",
".",
"Len",
"=",
"r",
".",
"NumPassed",
"+",
"r",
".",
"NumSkipped",
"+",
"r",
".",
"NumFailed",
"\n",
"}"
]
| // calcTotals calculates grand total for all suites | [
"calcTotals",
"calculates",
"grand",
"total",
"for",
"all",
"suites"
]
| a6d2debe0214087450ec59555dd656c9f76ef85e | https://github.com/tebeka/go2xunit/blob/a6d2debe0214087450ec59555dd656c9f76ef85e/lib/xmlout.go#L85-L97 |
11,598 | tebeka/go2xunit | lib/xmlout.go | WriteXML | 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 | 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
}
} | [
"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",
"(",
"\"",
"\"",
")",
",",
"RunTime",
":",
"testTime",
".",
"Format",
"(",
"\"",
"\"",
")",
",",
"Skipped",
":",
"Skipped",
",",
"Passed",
":",
"Passed",
",",
"Failed",
":",
"Failed",
",",
"}",
"\n",
"testsResult",
".",
"calcTotals",
"(",
")",
"\n",
"t",
":=",
"template",
".",
"New",
"(",
"\"",
"\"",
")",
".",
"Funcs",
"(",
"template",
".",
"FuncMap",
"{",
"\"",
"\"",
":",
"escapeForXML",
",",
"}",
")",
"\n\n",
"t",
",",
"err",
":=",
"t",
".",
"Parse",
"(",
"xml",
".",
"Header",
"+",
"xmlTemplate",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"err",
"=",
"t",
".",
"Execute",
"(",
"out",
",",
"testsResult",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}"
]
| // WriteXML exits xunit XML of tests to out | [
"WriteXML",
"exits",
"xunit",
"XML",
"of",
"tests",
"to",
"out"
]
| a6d2debe0214087450ec59555dd656c9f76ef85e | https://github.com/tebeka/go2xunit/blob/a6d2debe0214087450ec59555dd656c9f76ef85e/lib/xmlout.go#L108-L133 |
11,599 | hashicorp/go-checkpoint | telemetry.go | Report | 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 | 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
} | [
"func",
"Report",
"(",
"ctx",
"context",
".",
"Context",
",",
"r",
"*",
"ReportParams",
")",
"error",
"{",
"if",
"disabled",
":=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
";",
"disabled",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"req",
",",
"err",
":=",
"ReportRequest",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"client",
":=",
"cleanhttp",
".",
"DefaultClient",
"(",
")",
"\n",
"resp",
",",
"err",
":=",
"client",
".",
"Do",
"(",
"req",
".",
"WithContext",
"(",
"ctx",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"201",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"resp",
".",
"StatusCode",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // Report sends telemetry information to checkpoint | [
"Report",
"sends",
"telemetry",
"information",
"to",
"checkpoint"
]
| bbe6c410aa4be4194cb490a2bde8c3c33f295541 | https://github.com/hashicorp/go-checkpoint/blob/bbe6c410aa4be4194cb490a2bde8c3c33f295541/telemetry.go#L57-L77 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.