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 list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
17,800 | tobischo/gokeepasslib | xml.go | MarshalText | func (u UUID) MarshalText() ([]byte, error) {
text := make([]byte, 24)
base64.StdEncoding.Encode(text, u[:])
return text, nil
} | go | func (u UUID) MarshalText() ([]byte, error) {
text := make([]byte, 24)
base64.StdEncoding.Encode(text, u[:])
return text, nil
} | [
"func",
"(",
"u",
"UUID",
")",
"MarshalText",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"text",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"24",
")",
"\n",
"base64",
".",
"StdEncoding",
".",
"Encode",
"(",
"text",
",",
"u",
"[",
... | // MarshalText is a marshaler method to encode uuid content as base 64 and return it | [
"MarshalText",
"is",
"a",
"marshaler",
"method",
"to",
"encode",
"uuid",
"content",
"as",
"base",
"64",
"and",
"return",
"it"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/xml.go#L213-L217 |
17,801 | tobischo/gokeepasslib | xml.go | UnmarshalText | func (u *UUID) UnmarshalText(text []byte) error {
id := make([]byte, base64.StdEncoding.DecodedLen(len(text)))
length, err := base64.StdEncoding.Decode(id, text)
if err != nil {
return err
}
if length != 16 {
return ErrInvalidUUIDLength
}
copy((*u)[:], id[:16])
return nil
} | go | func (u *UUID) UnmarshalText(text []byte) error {
id := make([]byte, base64.StdEncoding.DecodedLen(len(text)))
length, err := base64.StdEncoding.Decode(id, text)
if err != nil {
return err
}
if length != 16 {
return ErrInvalidUUIDLength
}
copy((*u)[:], id[:16])
return nil
} | [
"func",
"(",
"u",
"*",
"UUID",
")",
"UnmarshalText",
"(",
"text",
"[",
"]",
"byte",
")",
"error",
"{",
"id",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"base64",
".",
"StdEncoding",
".",
"DecodedLen",
"(",
"len",
"(",
"text",
")",
")",
")",
"\n",
... | // UnmarshalText unmarshals a byte slice into a UUID by decoding the given data from base64 | [
"UnmarshalText",
"unmarshals",
"a",
"byte",
"slice",
"into",
"a",
"UUID",
"by",
"decoding",
"the",
"given",
"data",
"from",
"base64"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/xml.go#L220-L231 |
17,802 | tobischo/gokeepasslib | xml.go | Compare | func (u UUID) Compare(c UUID) bool {
for i, v := range c {
if u[i] != v {
return false
}
}
return true
} | go | func (u UUID) Compare(c UUID) bool {
for i, v := range c {
if u[i] != v {
return false
}
}
return true
} | [
"func",
"(",
"u",
"UUID",
")",
"Compare",
"(",
"c",
"UUID",
")",
"bool",
"{",
"for",
"i",
",",
"v",
":=",
"range",
"c",
"{",
"if",
"u",
"[",
"i",
"]",
"!=",
"v",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}... | // Compare allowes to check whether two instance of UUID are equal in value.
// This is used for searching a uuid | [
"Compare",
"allowes",
"to",
"check",
"whether",
"two",
"instance",
"of",
"UUID",
"are",
"equal",
"in",
"value",
".",
"This",
"is",
"used",
"for",
"searching",
"a",
"uuid"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/xml.go#L235-L242 |
17,803 | tobischo/gokeepasslib | xml.go | Get | func (e *Entry) Get(key string) *ValueData {
for i := range e.Values {
if e.Values[i].Key == key {
return &e.Values[i]
}
}
return nil
} | go | func (e *Entry) Get(key string) *ValueData {
for i := range e.Values {
if e.Values[i].Key == key {
return &e.Values[i]
}
}
return nil
} | [
"func",
"(",
"e",
"*",
"Entry",
")",
"Get",
"(",
"key",
"string",
")",
"*",
"ValueData",
"{",
"for",
"i",
":=",
"range",
"e",
".",
"Values",
"{",
"if",
"e",
".",
"Values",
"[",
"i",
"]",
".",
"Key",
"==",
"key",
"{",
"return",
"&",
"e",
".",
... | // Get returns the value in e corresponding with key k, or an empty string otherwise | [
"Get",
"returns",
"the",
"value",
"in",
"e",
"corresponding",
"with",
"key",
"k",
"or",
"an",
"empty",
"string",
"otherwise"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/xml.go#L245-L252 |
17,804 | tobischo/gokeepasslib | xml.go | GetContent | func (e *Entry) GetContent(key string) string {
val := e.Get(key)
if val == nil {
return ""
}
return val.Value.Content
} | go | func (e *Entry) GetContent(key string) string {
val := e.Get(key)
if val == nil {
return ""
}
return val.Value.Content
} | [
"func",
"(",
"e",
"*",
"Entry",
")",
"GetContent",
"(",
"key",
"string",
")",
"string",
"{",
"val",
":=",
"e",
".",
"Get",
"(",
"key",
")",
"\n",
"if",
"val",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"val",
".",
"Value... | // GetContent returns the content of the value belonging to the given key in string form | [
"GetContent",
"returns",
"the",
"content",
"of",
"the",
"value",
"belonging",
"to",
"the",
"given",
"key",
"in",
"string",
"form"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/xml.go#L255-L261 |
17,805 | tobischo/gokeepasslib | xml.go | GetIndex | func (e *Entry) GetIndex(key string) int {
for i := range e.Values {
if e.Values[i].Key == key {
return i
}
}
return -1
} | go | func (e *Entry) GetIndex(key string) int {
for i := range e.Values {
if e.Values[i].Key == key {
return i
}
}
return -1
} | [
"func",
"(",
"e",
"*",
"Entry",
")",
"GetIndex",
"(",
"key",
"string",
")",
"int",
"{",
"for",
"i",
":=",
"range",
"e",
".",
"Values",
"{",
"if",
"e",
".",
"Values",
"[",
"i",
"]",
".",
"Key",
"==",
"key",
"{",
"return",
"i",
"\n",
"}",
"\n",... | // GetIndex returns the index of the Value belonging to the given key, or -1 if none is found | [
"GetIndex",
"returns",
"the",
"index",
"of",
"the",
"Value",
"belonging",
"to",
"the",
"given",
"key",
"or",
"-",
"1",
"if",
"none",
"is",
"found"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/xml.go#L264-L271 |
17,806 | tobischo/gokeepasslib | database.go | getTransformedKey | func (db *Database) getTransformedKey() ([]byte, error) {
if db.Credentials == nil {
return nil, ErrRequiredAttributeMissing("Credentials")
}
return db.Credentials.buildTransformedKey(db)
} | go | func (db *Database) getTransformedKey() ([]byte, error) {
if db.Credentials == nil {
return nil, ErrRequiredAttributeMissing("Credentials")
}
return db.Credentials.buildTransformedKey(db)
} | [
"func",
"(",
"db",
"*",
"Database",
")",
"getTransformedKey",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"db",
".",
"Credentials",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrRequiredAttributeMissing",
"(",
"\"",
"\"",
")",
"\n",
... | // getTransformedKey returns the transformed key Credentials | [
"getTransformedKey",
"returns",
"the",
"transformed",
"key",
"Credentials"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/database.go#L42-L47 |
17,807 | tobischo/gokeepasslib | database.go | GetEncrypterManager | func (db *Database) GetEncrypterManager(transformedKey []byte) (*EncrypterManager, error) {
return NewEncrypterManager(
buildMasterKey(db, transformedKey),
db.Header.FileHeaders.EncryptionIV,
)
} | go | func (db *Database) GetEncrypterManager(transformedKey []byte) (*EncrypterManager, error) {
return NewEncrypterManager(
buildMasterKey(db, transformedKey),
db.Header.FileHeaders.EncryptionIV,
)
} | [
"func",
"(",
"db",
"*",
"Database",
")",
"GetEncrypterManager",
"(",
"transformedKey",
"[",
"]",
"byte",
")",
"(",
"*",
"EncrypterManager",
",",
"error",
")",
"{",
"return",
"NewEncrypterManager",
"(",
"buildMasterKey",
"(",
"db",
",",
"transformedKey",
")",
... | // GetEncrypterManager returns an EncryptManager based on the master key and EncryptionIV, or nil if the type is unsupported | [
"GetEncrypterManager",
"returns",
"an",
"EncryptManager",
"based",
"on",
"the",
"master",
"key",
"and",
"EncryptionIV",
"or",
"nil",
"if",
"the",
"type",
"is",
"unsupported"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/database.go#L50-L55 |
17,808 | tobischo/gokeepasslib | database.go | GetStreamManager | func (db *Database) GetStreamManager() (*StreamManager, error) {
if db.Header.FileHeaders != nil {
if db.Header.IsKdbx4() {
return NewStreamManager(
db.Content.InnerHeader.InnerRandomStreamID,
db.Content.InnerHeader.InnerRandomStreamKey,
)
}
return NewStreamManager(
db.Header.FileHeaders.InnerRandomStreamID,
db.Header.FileHeaders.ProtectedStreamKey,
)
}
return nil, nil
} | go | func (db *Database) GetStreamManager() (*StreamManager, error) {
if db.Header.FileHeaders != nil {
if db.Header.IsKdbx4() {
return NewStreamManager(
db.Content.InnerHeader.InnerRandomStreamID,
db.Content.InnerHeader.InnerRandomStreamKey,
)
}
return NewStreamManager(
db.Header.FileHeaders.InnerRandomStreamID,
db.Header.FileHeaders.ProtectedStreamKey,
)
}
return nil, nil
} | [
"func",
"(",
"db",
"*",
"Database",
")",
"GetStreamManager",
"(",
")",
"(",
"*",
"StreamManager",
",",
"error",
")",
"{",
"if",
"db",
".",
"Header",
".",
"FileHeaders",
"!=",
"nil",
"{",
"if",
"db",
".",
"Header",
".",
"IsKdbx4",
"(",
")",
"{",
"re... | // GetStreamManager returns a StreamManager based on the db headers, or nil if the type is unsupported
// Can be used to lock only certain entries instead of calling | [
"GetStreamManager",
"returns",
"a",
"StreamManager",
"based",
"on",
"the",
"db",
"headers",
"or",
"nil",
"if",
"the",
"type",
"is",
"unsupported",
"Can",
"be",
"used",
"to",
"lock",
"only",
"certain",
"entries",
"instead",
"of",
"calling"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/database.go#L59-L74 |
17,809 | tobischo/gokeepasslib | binary.go | Find | func (bs Binaries) Find(id int) *Binary {
for i := range bs {
if bs[i].ID == id {
return &bs[i]
}
}
return nil
} | go | func (bs Binaries) Find(id int) *Binary {
for i := range bs {
if bs[i].ID == id {
return &bs[i]
}
}
return nil
} | [
"func",
"(",
"bs",
"Binaries",
")",
"Find",
"(",
"id",
"int",
")",
"*",
"Binary",
"{",
"for",
"i",
":=",
"range",
"bs",
"{",
"if",
"bs",
"[",
"i",
"]",
".",
"ID",
"==",
"id",
"{",
"return",
"&",
"bs",
"[",
"i",
"]",
"\n",
"}",
"\n",
"}",
... | // Find returns a reference to a binary with the same ID as id, or nil if none if found | [
"Find",
"returns",
"a",
"reference",
"to",
"a",
"binary",
"with",
"the",
"same",
"ID",
"as",
"id",
"or",
"nil",
"if",
"none",
"if",
"found"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/binary.go#L36-L43 |
17,810 | tobischo/gokeepasslib | binary.go | Find | func (br *BinaryReference) Find(db *Database) *Binary {
if db.Header.IsKdbx4() {
return db.Content.InnerHeader.Binaries.Find(br.Value.ID)
}
return db.Content.Meta.Binaries.Find(br.Value.ID)
} | go | func (br *BinaryReference) Find(db *Database) *Binary {
if db.Header.IsKdbx4() {
return db.Content.InnerHeader.Binaries.Find(br.Value.ID)
}
return db.Content.Meta.Binaries.Find(br.Value.ID)
} | [
"func",
"(",
"br",
"*",
"BinaryReference",
")",
"Find",
"(",
"db",
"*",
"Database",
")",
"*",
"Binary",
"{",
"if",
"db",
".",
"Header",
".",
"IsKdbx4",
"(",
")",
"{",
"return",
"db",
".",
"Content",
".",
"InnerHeader",
".",
"Binaries",
".",
"Find",
... | // Find returns a reference to a binary in the database db with the same id as br, or nil if none is found | [
"Find",
"returns",
"a",
"reference",
"to",
"a",
"binary",
"in",
"the",
"database",
"db",
"with",
"the",
"same",
"id",
"as",
"br",
"or",
"nil",
"if",
"none",
"is",
"found"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/binary.go#L46-L51 |
17,811 | tobischo/gokeepasslib | binary.go | Add | func (bs *Binaries) Add(c []byte) *Binary {
binary := Binary{
Compressed: wrappers.BoolWrapper(true),
}
if len(*bs) == 0 {
binary.ID = 0
} else {
binary.ID = (*bs)[len(*bs)-1].ID + 1
}
binary.SetContent(c)
*bs = append(*bs, binary)
return &(*bs)[len(*bs)-1]
} | go | func (bs *Binaries) Add(c []byte) *Binary {
binary := Binary{
Compressed: wrappers.BoolWrapper(true),
}
if len(*bs) == 0 {
binary.ID = 0
} else {
binary.ID = (*bs)[len(*bs)-1].ID + 1
}
binary.SetContent(c)
*bs = append(*bs, binary)
return &(*bs)[len(*bs)-1]
} | [
"func",
"(",
"bs",
"*",
"Binaries",
")",
"Add",
"(",
"c",
"[",
"]",
"byte",
")",
"*",
"Binary",
"{",
"binary",
":=",
"Binary",
"{",
"Compressed",
":",
"wrappers",
".",
"BoolWrapper",
"(",
"true",
")",
",",
"}",
"\n",
"if",
"len",
"(",
"*",
"bs",
... | // Add appends binary data to the slice | [
"Add",
"appends",
"binary",
"data",
"to",
"the",
"slice"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/binary.go#L54-L66 |
17,812 | tobischo/gokeepasslib | binary.go | GetContent | func (b Binary) GetContent() (string, error) {
// Check for base64 content (KDBX 3.1), if it fail try with KDBX 4
decoded := make([]byte, base64.StdEncoding.DecodedLen(len(b.Content)))
_, err := base64.StdEncoding.Decode(decoded, b.Content)
if err != nil {
// KDBX 4 doesn't encode it
decoded = b.Content[:]
}
if b.Compressed {
reader, err := gzip.NewReader(bytes.NewReader(decoded))
if err != nil {
return "", err
}
defer reader.Close()
bts, err := ioutil.ReadAll(reader)
if err != nil && err != io.ErrUnexpectedEOF {
return "", err
}
return string(bts), nil
}
return string(decoded), nil
} | go | func (b Binary) GetContent() (string, error) {
// Check for base64 content (KDBX 3.1), if it fail try with KDBX 4
decoded := make([]byte, base64.StdEncoding.DecodedLen(len(b.Content)))
_, err := base64.StdEncoding.Decode(decoded, b.Content)
if err != nil {
// KDBX 4 doesn't encode it
decoded = b.Content[:]
}
if b.Compressed {
reader, err := gzip.NewReader(bytes.NewReader(decoded))
if err != nil {
return "", err
}
defer reader.Close()
bts, err := ioutil.ReadAll(reader)
if err != nil && err != io.ErrUnexpectedEOF {
return "", err
}
return string(bts), nil
}
return string(decoded), nil
} | [
"func",
"(",
"b",
"Binary",
")",
"GetContent",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"// Check for base64 content (KDBX 3.1), if it fail try with KDBX 4",
"decoded",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"base64",
".",
"StdEncoding",
".",
"Decoded... | // GetContent returns a string which is the plaintext content of a binary | [
"GetContent",
"returns",
"a",
"string",
"which",
"is",
"the",
"plaintext",
"content",
"of",
"a",
"binary"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/binary.go#L69-L91 |
17,813 | tobischo/gokeepasslib | binary.go | CreateReference | func (b Binary) CreateReference(f string) BinaryReference {
return NewBinaryReference(f, b.ID)
} | go | func (b Binary) CreateReference(f string) BinaryReference {
return NewBinaryReference(f, b.ID)
} | [
"func",
"(",
"b",
"Binary",
")",
"CreateReference",
"(",
"f",
"string",
")",
"BinaryReference",
"{",
"return",
"NewBinaryReference",
"(",
"f",
",",
"b",
".",
"ID",
")",
"\n",
"}"
] | // CreateReference creates a reference with the same id as b with filename f | [
"CreateReference",
"creates",
"a",
"reference",
"with",
"the",
"same",
"id",
"as",
"b",
"with",
"filename",
"f"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/binary.go#L112-L114 |
17,814 | tobischo/gokeepasslib | binary.go | NewBinaryReference | func NewBinaryReference(name string, id int) BinaryReference {
ref := BinaryReference{}
ref.Name = name
ref.Value.ID = id
return ref
} | go | func NewBinaryReference(name string, id int) BinaryReference {
ref := BinaryReference{}
ref.Name = name
ref.Value.ID = id
return ref
} | [
"func",
"NewBinaryReference",
"(",
"name",
"string",
",",
"id",
"int",
")",
"BinaryReference",
"{",
"ref",
":=",
"BinaryReference",
"{",
"}",
"\n",
"ref",
".",
"Name",
"=",
"name",
"\n",
"ref",
".",
"Value",
".",
"ID",
"=",
"id",
"\n",
"return",
"ref",... | // NewBinaryReference creates a new BinaryReference with the given name and id | [
"NewBinaryReference",
"creates",
"a",
"new",
"BinaryReference",
"with",
"the",
"given",
"name",
"and",
"id"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/binary.go#L117-L122 |
17,815 | tobischo/gokeepasslib | content.go | readFrom | func (ih *InnerHeader) readFrom(r io.Reader) error {
binaryCount := 0 // Var used to count and index every binary
for {
var headerType byte
var length int32
var data []byte
if err := binary.Read(r, binary.LittleEndian, &headerType); err != nil {
return err
}
if err := binary.Read(r, binary.LittleEndian, &length); err != nil {
return err
}
data = make([]byte, length)
if err := binary.Read(r, binary.LittleEndian, &data); err != nil {
return err
}
if headerType == InnerHeaderTerminator {
// End of inner header
break
} else if headerType == InnerHeaderIRSID {
// Found InnerRandomStream ID
ih.InnerRandomStreamID = binary.LittleEndian.Uint32(data)
} else if headerType == InnerHeaderIRSKey {
// Found InnerRandomStream Key
ih.InnerRandomStreamKey = data
} else if headerType == InnerHeaderBinary {
// Found a binary
var protection byte
reader := bytes.NewReader(data)
binary.Read(reader, binary.LittleEndian, &protection) // Read memory protection flag
content, _ := ioutil.ReadAll(reader) // Read content
ih.Binaries = append(ih.Binaries, Binary{
ID: binaryCount,
MemoryProtection: protection,
Content: content,
})
binaryCount = binaryCount + 1
} else {
return ErrUnknownInnerHeaderID(headerType)
}
}
return nil
} | go | func (ih *InnerHeader) readFrom(r io.Reader) error {
binaryCount := 0 // Var used to count and index every binary
for {
var headerType byte
var length int32
var data []byte
if err := binary.Read(r, binary.LittleEndian, &headerType); err != nil {
return err
}
if err := binary.Read(r, binary.LittleEndian, &length); err != nil {
return err
}
data = make([]byte, length)
if err := binary.Read(r, binary.LittleEndian, &data); err != nil {
return err
}
if headerType == InnerHeaderTerminator {
// End of inner header
break
} else if headerType == InnerHeaderIRSID {
// Found InnerRandomStream ID
ih.InnerRandomStreamID = binary.LittleEndian.Uint32(data)
} else if headerType == InnerHeaderIRSKey {
// Found InnerRandomStream Key
ih.InnerRandomStreamKey = data
} else if headerType == InnerHeaderBinary {
// Found a binary
var protection byte
reader := bytes.NewReader(data)
binary.Read(reader, binary.LittleEndian, &protection) // Read memory protection flag
content, _ := ioutil.ReadAll(reader) // Read content
ih.Binaries = append(ih.Binaries, Binary{
ID: binaryCount,
MemoryProtection: protection,
Content: content,
})
binaryCount = binaryCount + 1
} else {
return ErrUnknownInnerHeaderID(headerType)
}
}
return nil
} | [
"func",
"(",
"ih",
"*",
"InnerHeader",
")",
"readFrom",
"(",
"r",
"io",
".",
"Reader",
")",
"error",
"{",
"binaryCount",
":=",
"0",
"// Var used to count and index every binary",
"\n",
"for",
"{",
"var",
"headerType",
"byte",
"\n",
"var",
"length",
"int32",
... | // readFrom reads the InnerHeader from an io.Reader | [
"readFrom",
"reads",
"the",
"InnerHeader",
"from",
"an",
"io",
".",
"Reader"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/content.go#L47-L94 |
17,816 | tobischo/gokeepasslib | content.go | writeTo | func (ih *InnerHeader) writeTo(w io.Writer) error {
irsID := make([]byte, 4)
binary.LittleEndian.PutUint32(irsID, ih.InnerRandomStreamID)
if err := writeToInnerHeader(w, InnerHeaderIRSID, irsID); err != nil {
return err
}
if err := writeToInnerHeader(w, InnerHeaderIRSKey, ih.InnerRandomStreamKey); err != nil {
return err
}
for _, item := range ih.Binaries {
buf := []byte{item.MemoryProtection}
buf = append(buf, item.Content...)
if err := writeToInnerHeader(w, InnerHeaderBinary, buf); err != nil {
return err
}
}
// End inner header
if err := binary.Write(w, binary.LittleEndian, InnerHeaderTerminator); err != nil {
return err
}
return binary.Write(w, binary.LittleEndian, uint32(0))
} | go | func (ih *InnerHeader) writeTo(w io.Writer) error {
irsID := make([]byte, 4)
binary.LittleEndian.PutUint32(irsID, ih.InnerRandomStreamID)
if err := writeToInnerHeader(w, InnerHeaderIRSID, irsID); err != nil {
return err
}
if err := writeToInnerHeader(w, InnerHeaderIRSKey, ih.InnerRandomStreamKey); err != nil {
return err
}
for _, item := range ih.Binaries {
buf := []byte{item.MemoryProtection}
buf = append(buf, item.Content...)
if err := writeToInnerHeader(w, InnerHeaderBinary, buf); err != nil {
return err
}
}
// End inner header
if err := binary.Write(w, binary.LittleEndian, InnerHeaderTerminator); err != nil {
return err
}
return binary.Write(w, binary.LittleEndian, uint32(0))
} | [
"func",
"(",
"ih",
"*",
"InnerHeader",
")",
"writeTo",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"irsID",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"4",
")",
"\n",
"binary",
".",
"LittleEndian",
".",
"PutUint32",
"(",
"irsID",
",",
"ih",
... | // writeTo the InnerHeader to the given io.Writer | [
"writeTo",
"the",
"InnerHeader",
"to",
"the",
"given",
"io",
".",
"Writer"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/content.go#L97-L120 |
17,817 | tobischo/gokeepasslib | hashes.go | readFrom | func (h *DBHashes) readFrom(r io.Reader) error {
return binary.Read(r, binary.LittleEndian, h)
} | go | func (h *DBHashes) readFrom(r io.Reader) error {
return binary.Read(r, binary.LittleEndian, h)
} | [
"func",
"(",
"h",
"*",
"DBHashes",
")",
"readFrom",
"(",
"r",
"io",
".",
"Reader",
")",
"error",
"{",
"return",
"binary",
".",
"Read",
"(",
"r",
",",
"binary",
".",
"LittleEndian",
",",
"h",
")",
"\n",
"}"
] | // readFrom reads the hashes from an io.Reader | [
"readFrom",
"reads",
"the",
"hashes",
"from",
"an",
"io",
".",
"Reader"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/hashes.go#L23-L25 |
17,818 | tobischo/gokeepasslib | hashes.go | writeTo | func (h DBHashes) writeTo(w io.Writer) error {
return binary.Write(w, binary.LittleEndian, h)
} | go | func (h DBHashes) writeTo(w io.Writer) error {
return binary.Write(w, binary.LittleEndian, h)
} | [
"func",
"(",
"h",
"DBHashes",
")",
"writeTo",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"return",
"binary",
".",
"Write",
"(",
"w",
",",
"binary",
".",
"LittleEndian",
",",
"h",
")",
"\n",
"}"
] | // writeTo writes the hashes to the given io.Writer | [
"writeTo",
"writes",
"the",
"hashes",
"to",
"the",
"given",
"io",
".",
"Writer"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/hashes.go#L28-L30 |
17,819 | tobischo/gokeepasslib | wrappers/time.go | Now | func Now() TimeWrapper {
return TimeWrapper{
Formatted: true,
Time: time.Now().In(time.UTC),
}
} | go | func Now() TimeWrapper {
return TimeWrapper{
Formatted: true,
Time: time.Now().In(time.UTC),
}
} | [
"func",
"Now",
"(",
")",
"TimeWrapper",
"{",
"return",
"TimeWrapper",
"{",
"Formatted",
":",
"true",
",",
"Time",
":",
"time",
".",
"Now",
"(",
")",
".",
"In",
"(",
"time",
".",
"UTC",
")",
",",
"}",
"\n",
"}"
] | // Now returns a TimeWrapper instance with the current time in UTC | [
"Now",
"returns",
"a",
"TimeWrapper",
"instance",
"with",
"the",
"current",
"time",
"in",
"UTC"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/wrappers/time.go#L22-L27 |
17,820 | tobischo/gokeepasslib | crypto/aes.go | NewAESEncrypter | func NewAESEncrypter(key []byte, iv []byte) (*AESEncrypter, error) {
block, err := aes.NewCipher(key)
if err != nil {
return nil, err
}
e := AESEncrypter{
block: block,
encryptionIV: iv,
}
return &e, nil
} | go | func NewAESEncrypter(key []byte, iv []byte) (*AESEncrypter, error) {
block, err := aes.NewCipher(key)
if err != nil {
return nil, err
}
e := AESEncrypter{
block: block,
encryptionIV: iv,
}
return &e, nil
} | [
"func",
"NewAESEncrypter",
"(",
"key",
"[",
"]",
"byte",
",",
"iv",
"[",
"]",
"byte",
")",
"(",
"*",
"AESEncrypter",
",",
"error",
")",
"{",
"block",
",",
"err",
":=",
"aes",
".",
"NewCipher",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",... | // NewAESEncrypter initialize a new AESEncrypter interfaced with Encrypter | [
"NewAESEncrypter",
"initialize",
"a",
"new",
"AESEncrypter",
"interfaced",
"with",
"Encrypter"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/crypto/aes.go#L15-L26 |
17,821 | tobischo/gokeepasslib | crypto/chacha.go | NewChaChaEncrypter | func NewChaChaEncrypter(key []byte, iv []byte) (*ChaChaStream, error) {
cipher, err := chacha20.NewCipher(iv, key)
if err != nil {
return nil, err
}
c := ChaChaStream{
cipher: cipher,
}
return &c, nil
} | go | func NewChaChaEncrypter(key []byte, iv []byte) (*ChaChaStream, error) {
cipher, err := chacha20.NewCipher(iv, key)
if err != nil {
return nil, err
}
c := ChaChaStream{
cipher: cipher,
}
return &c, nil
} | [
"func",
"NewChaChaEncrypter",
"(",
"key",
"[",
"]",
"byte",
",",
"iv",
"[",
"]",
"byte",
")",
"(",
"*",
"ChaChaStream",
",",
"error",
")",
"{",
"cipher",
",",
"err",
":=",
"chacha20",
".",
"NewCipher",
"(",
"iv",
",",
"key",
")",
"\n",
"if",
"err",... | // NewChaChaEncrypter initialize a new ChaChaStream interfaced with Encrypter | [
"NewChaChaEncrypter",
"initialize",
"a",
"new",
"ChaChaStream",
"interfaced",
"with",
"Encrypter"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/crypto/chacha.go#L17-L27 |
17,822 | tobischo/gokeepasslib | crypto/chacha.go | NewChaChaStream | func NewChaChaStream(key []byte) (*ChaChaStream, error) {
hash := sha512.Sum512(key)
cipher, err := chacha20.NewCipher(hash[32:44], hash[:32])
if err != nil {
return nil, err
}
c := ChaChaStream{
cipher: cipher,
}
return &c, nil
} | go | func NewChaChaStream(key []byte) (*ChaChaStream, error) {
hash := sha512.Sum512(key)
cipher, err := chacha20.NewCipher(hash[32:44], hash[:32])
if err != nil {
return nil, err
}
c := ChaChaStream{
cipher: cipher,
}
return &c, nil
} | [
"func",
"NewChaChaStream",
"(",
"key",
"[",
"]",
"byte",
")",
"(",
"*",
"ChaChaStream",
",",
"error",
")",
"{",
"hash",
":=",
"sha512",
".",
"Sum512",
"(",
"key",
")",
"\n\n",
"cipher",
",",
"err",
":=",
"chacha20",
".",
"NewCipher",
"(",
"hash",
"["... | // NewChaChaStream initialize a new ChaChaStream interfaced with Stream | [
"NewChaChaStream",
"initialize",
"a",
"new",
"ChaChaStream",
"interfaced",
"with",
"Stream"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/crypto/chacha.go#L30-L42 |
17,823 | tobischo/gokeepasslib | wrappers/bool.go | MarshalXML | func (b *BoolWrapper) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
val := "False"
if *b {
val = "True"
}
e.EncodeElement(val, start)
return nil
} | go | func (b *BoolWrapper) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
val := "False"
if *b {
val = "True"
}
e.EncodeElement(val, start)
return nil
} | [
"func",
"(",
"b",
"*",
"BoolWrapper",
")",
"MarshalXML",
"(",
"e",
"*",
"xml",
".",
"Encoder",
",",
"start",
"xml",
".",
"StartElement",
")",
"error",
"{",
"val",
":=",
"\"",
"\"",
"\n",
"if",
"*",
"b",
"{",
"val",
"=",
"\"",
"\"",
"\n",
"}",
"... | // MarshalXML marshals the boolean into e | [
"MarshalXML",
"marshals",
"the",
"boolean",
"into",
"e"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/wrappers/bool.go#L12-L19 |
17,824 | tobischo/gokeepasslib | wrappers/bool.go | UnmarshalXML | func (b *BoolWrapper) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var val string
d.DecodeElement(&val, &start)
*b = false
if strings.ToLower(val) == "true" {
*b = true
}
return nil
} | go | func (b *BoolWrapper) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var val string
d.DecodeElement(&val, &start)
*b = false
if strings.ToLower(val) == "true" {
*b = true
}
return nil
} | [
"func",
"(",
"b",
"*",
"BoolWrapper",
")",
"UnmarshalXML",
"(",
"d",
"*",
"xml",
".",
"Decoder",
",",
"start",
"xml",
".",
"StartElement",
")",
"error",
"{",
"var",
"val",
"string",
"\n",
"d",
".",
"DecodeElement",
"(",
"&",
"val",
",",
"&",
"start",... | // UnmarshalXML unmarshals the boolean from d | [
"UnmarshalXML",
"unmarshals",
"the",
"boolean",
"from",
"d"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/wrappers/bool.go#L22-L32 |
17,825 | tobischo/gokeepasslib | wrappers/bool.go | MarshalXMLAttr | func (b *BoolWrapper) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
val := "False"
if *b {
val = "True"
}
return xml.Attr{Name: name, Value: val}, nil
} | go | func (b *BoolWrapper) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
val := "False"
if *b {
val = "True"
}
return xml.Attr{Name: name, Value: val}, nil
} | [
"func",
"(",
"b",
"*",
"BoolWrapper",
")",
"MarshalXMLAttr",
"(",
"name",
"xml",
".",
"Name",
")",
"(",
"xml",
".",
"Attr",
",",
"error",
")",
"{",
"val",
":=",
"\"",
"\"",
"\n",
"if",
"*",
"b",
"{",
"val",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
... | // MarshalXMLAttr returns the encoded XML attribute | [
"MarshalXMLAttr",
"returns",
"the",
"encoded",
"XML",
"attribute"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/wrappers/bool.go#L35-L42 |
17,826 | tobischo/gokeepasslib | wrappers/bool.go | UnmarshalXMLAttr | func (b *BoolWrapper) UnmarshalXMLAttr(attr xml.Attr) error {
*b = false
if strings.ToLower(attr.Value) == "true" {
*b = true
}
return nil
} | go | func (b *BoolWrapper) UnmarshalXMLAttr(attr xml.Attr) error {
*b = false
if strings.ToLower(attr.Value) == "true" {
*b = true
}
return nil
} | [
"func",
"(",
"b",
"*",
"BoolWrapper",
")",
"UnmarshalXMLAttr",
"(",
"attr",
"xml",
".",
"Attr",
")",
"error",
"{",
"*",
"b",
"=",
"false",
"\n",
"if",
"strings",
".",
"ToLower",
"(",
"attr",
".",
"Value",
")",
"==",
"\"",
"\"",
"{",
"*",
"b",
"="... | // UnmarshalXMLAttr decodes a single XML attribute | [
"UnmarshalXMLAttr",
"decodes",
"a",
"single",
"XML",
"attribute"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/wrappers/bool.go#L45-L52 |
17,827 | tobischo/gokeepasslib | crypto.go | NewEncrypterManager | func NewEncrypterManager(key []byte, iv []byte) (manager *EncrypterManager, err error) {
var encrypter Encrypter
manager = new(EncrypterManager)
switch len(iv) {
case 12:
// ChaCha20
encrypter, err = crypto.NewChaChaEncrypter(key, iv)
case 16:
// AES
encrypter, err = crypto.NewAESEncrypter(key, iv)
default:
return nil, ErrUnsupportedEncrypterType
}
manager.Encrypter = encrypter
return
} | go | func NewEncrypterManager(key []byte, iv []byte) (manager *EncrypterManager, err error) {
var encrypter Encrypter
manager = new(EncrypterManager)
switch len(iv) {
case 12:
// ChaCha20
encrypter, err = crypto.NewChaChaEncrypter(key, iv)
case 16:
// AES
encrypter, err = crypto.NewAESEncrypter(key, iv)
default:
return nil, ErrUnsupportedEncrypterType
}
manager.Encrypter = encrypter
return
} | [
"func",
"NewEncrypterManager",
"(",
"key",
"[",
"]",
"byte",
",",
"iv",
"[",
"]",
"byte",
")",
"(",
"manager",
"*",
"EncrypterManager",
",",
"err",
"error",
")",
"{",
"var",
"encrypter",
"Encrypter",
"\n",
"manager",
"=",
"new",
"(",
"EncrypterManager",
... | // NewEncrypterManager initialize a new EncrypterManager | [
"NewEncrypterManager",
"initialize",
"a",
"new",
"EncrypterManager"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/crypto.go#L40-L55 |
17,828 | tobischo/gokeepasslib | crypto.go | NewStreamManager | func NewStreamManager(id uint32, key []byte) (manager *StreamManager, err error) {
var stream Stream
manager = new(StreamManager)
switch id {
case NoStreamID:
stream = crypto.NewInsecureStream()
case SalsaStreamID:
stream, err = crypto.NewSalsaStream(key)
case ChaChaStreamID:
stream, err = crypto.NewChaChaStream(key)
default:
return nil, ErrUnsupportedStreamType
}
manager.Stream = stream
return
} | go | func NewStreamManager(id uint32, key []byte) (manager *StreamManager, err error) {
var stream Stream
manager = new(StreamManager)
switch id {
case NoStreamID:
stream = crypto.NewInsecureStream()
case SalsaStreamID:
stream, err = crypto.NewSalsaStream(key)
case ChaChaStreamID:
stream, err = crypto.NewChaChaStream(key)
default:
return nil, ErrUnsupportedStreamType
}
manager.Stream = stream
return
} | [
"func",
"NewStreamManager",
"(",
"id",
"uint32",
",",
"key",
"[",
"]",
"byte",
")",
"(",
"manager",
"*",
"StreamManager",
",",
"err",
"error",
")",
"{",
"var",
"stream",
"Stream",
"\n",
"manager",
"=",
"new",
"(",
"StreamManager",
")",
"\n",
"switch",
... | // NewStreamManager initialize a new StreamManager | [
"NewStreamManager",
"initialize",
"a",
"new",
"StreamManager"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/crypto.go#L58-L73 |
17,829 | tobischo/gokeepasslib | crypto.go | UnlockProtectedGroups | func (cs *StreamManager) UnlockProtectedGroups(gs []Group) {
for i := range gs { //For each top level group
cs.UnlockProtectedGroup(&gs[i])
}
} | go | func (cs *StreamManager) UnlockProtectedGroups(gs []Group) {
for i := range gs { //For each top level group
cs.UnlockProtectedGroup(&gs[i])
}
} | [
"func",
"(",
"cs",
"*",
"StreamManager",
")",
"UnlockProtectedGroups",
"(",
"gs",
"[",
"]",
"Group",
")",
"{",
"for",
"i",
":=",
"range",
"gs",
"{",
"//For each top level group",
"cs",
".",
"UnlockProtectedGroup",
"(",
"&",
"gs",
"[",
"i",
"]",
")",
"\n"... | // UnlockProtectedGroups unlocks an array of protected groups | [
"UnlockProtectedGroups",
"unlocks",
"an",
"array",
"of",
"protected",
"groups"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/crypto.go#L96-L100 |
17,830 | tobischo/gokeepasslib | crypto.go | UnlockProtectedGroup | func (cs *StreamManager) UnlockProtectedGroup(g *Group) {
cs.UnlockProtectedEntries(g.Entries)
cs.UnlockProtectedGroups(g.Groups)
} | go | func (cs *StreamManager) UnlockProtectedGroup(g *Group) {
cs.UnlockProtectedEntries(g.Entries)
cs.UnlockProtectedGroups(g.Groups)
} | [
"func",
"(",
"cs",
"*",
"StreamManager",
")",
"UnlockProtectedGroup",
"(",
"g",
"*",
"Group",
")",
"{",
"cs",
".",
"UnlockProtectedEntries",
"(",
"g",
".",
"Entries",
")",
"\n",
"cs",
".",
"UnlockProtectedGroups",
"(",
"g",
".",
"Groups",
")",
"\n",
"}"
... | // UnlockProtectedGroup unlocks a protected group | [
"UnlockProtectedGroup",
"unlocks",
"a",
"protected",
"group"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/crypto.go#L103-L106 |
17,831 | tobischo/gokeepasslib | crypto.go | UnlockProtectedEntries | func (cs *StreamManager) UnlockProtectedEntries(e []Entry) {
for i := range e {
cs.UnlockProtectedEntry(&e[i])
}
} | go | func (cs *StreamManager) UnlockProtectedEntries(e []Entry) {
for i := range e {
cs.UnlockProtectedEntry(&e[i])
}
} | [
"func",
"(",
"cs",
"*",
"StreamManager",
")",
"UnlockProtectedEntries",
"(",
"e",
"[",
"]",
"Entry",
")",
"{",
"for",
"i",
":=",
"range",
"e",
"{",
"cs",
".",
"UnlockProtectedEntry",
"(",
"&",
"e",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"}"
] | // UnlockProtectedEntries unlocks an array of protected entries | [
"UnlockProtectedEntries",
"unlocks",
"an",
"array",
"of",
"protected",
"entries"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/crypto.go#L109-L113 |
17,832 | tobischo/gokeepasslib | crypto.go | UnlockProtectedEntry | func (cs *StreamManager) UnlockProtectedEntry(e *Entry) {
for i := range e.Values {
if bool(e.Values[i].Value.Protected) {
e.Values[i].Value.Content = string(cs.Unpack(e.Values[i].Value.Content))
}
}
for i := range e.Histories {
cs.UnlockProtectedEntries(e.Histories[i].Entries)
}
} | go | func (cs *StreamManager) UnlockProtectedEntry(e *Entry) {
for i := range e.Values {
if bool(e.Values[i].Value.Protected) {
e.Values[i].Value.Content = string(cs.Unpack(e.Values[i].Value.Content))
}
}
for i := range e.Histories {
cs.UnlockProtectedEntries(e.Histories[i].Entries)
}
} | [
"func",
"(",
"cs",
"*",
"StreamManager",
")",
"UnlockProtectedEntry",
"(",
"e",
"*",
"Entry",
")",
"{",
"for",
"i",
":=",
"range",
"e",
".",
"Values",
"{",
"if",
"bool",
"(",
"e",
".",
"Values",
"[",
"i",
"]",
".",
"Value",
".",
"Protected",
")",
... | // UnlockProtectedEntry unlocks a protected entry | [
"UnlockProtectedEntry",
"unlocks",
"a",
"protected",
"entry"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/crypto.go#L116-L125 |
17,833 | tobischo/gokeepasslib | crypto.go | LockProtectedGroups | func (cs *StreamManager) LockProtectedGroups(gs []Group) {
for i := range gs {
cs.LockProtectedGroup(&gs[i])
}
} | go | func (cs *StreamManager) LockProtectedGroups(gs []Group) {
for i := range gs {
cs.LockProtectedGroup(&gs[i])
}
} | [
"func",
"(",
"cs",
"*",
"StreamManager",
")",
"LockProtectedGroups",
"(",
"gs",
"[",
"]",
"Group",
")",
"{",
"for",
"i",
":=",
"range",
"gs",
"{",
"cs",
".",
"LockProtectedGroup",
"(",
"&",
"gs",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"}"
] | // LockProtectedGroups locks an array of unprotected groups | [
"LockProtectedGroups",
"locks",
"an",
"array",
"of",
"unprotected",
"groups"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/crypto.go#L128-L132 |
17,834 | tobischo/gokeepasslib | crypto.go | LockProtectedGroup | func (cs *StreamManager) LockProtectedGroup(g *Group) {
cs.LockProtectedEntries(g.Entries)
cs.LockProtectedGroups(g.Groups)
} | go | func (cs *StreamManager) LockProtectedGroup(g *Group) {
cs.LockProtectedEntries(g.Entries)
cs.LockProtectedGroups(g.Groups)
} | [
"func",
"(",
"cs",
"*",
"StreamManager",
")",
"LockProtectedGroup",
"(",
"g",
"*",
"Group",
")",
"{",
"cs",
".",
"LockProtectedEntries",
"(",
"g",
".",
"Entries",
")",
"\n",
"cs",
".",
"LockProtectedGroups",
"(",
"g",
".",
"Groups",
")",
"\n",
"}"
] | // LockProtectedGroup locks an unprotected group | [
"LockProtectedGroup",
"locks",
"an",
"unprotected",
"group"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/crypto.go#L135-L138 |
17,835 | tobischo/gokeepasslib | crypto.go | LockProtectedEntries | func (cs *StreamManager) LockProtectedEntries(es []Entry) {
for i := range es {
cs.LockProtectedEntry(&es[i])
}
} | go | func (cs *StreamManager) LockProtectedEntries(es []Entry) {
for i := range es {
cs.LockProtectedEntry(&es[i])
}
} | [
"func",
"(",
"cs",
"*",
"StreamManager",
")",
"LockProtectedEntries",
"(",
"es",
"[",
"]",
"Entry",
")",
"{",
"for",
"i",
":=",
"range",
"es",
"{",
"cs",
".",
"LockProtectedEntry",
"(",
"&",
"es",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"}"
] | // LockProtectedEntries locks an array of unprotected entries | [
"LockProtectedEntries",
"locks",
"an",
"array",
"of",
"unprotected",
"entries"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/crypto.go#L141-L145 |
17,836 | tobischo/gokeepasslib | crypto.go | LockProtectedEntry | func (cs *StreamManager) LockProtectedEntry(e *Entry) {
for i := range e.Values {
if bool(e.Values[i].Value.Protected) {
e.Values[i].Value.Content = cs.Pack([]byte(e.Values[i].Value.Content))
}
}
for i := range e.Histories {
cs.LockProtectedEntries(e.Histories[i].Entries)
}
} | go | func (cs *StreamManager) LockProtectedEntry(e *Entry) {
for i := range e.Values {
if bool(e.Values[i].Value.Protected) {
e.Values[i].Value.Content = cs.Pack([]byte(e.Values[i].Value.Content))
}
}
for i := range e.Histories {
cs.LockProtectedEntries(e.Histories[i].Entries)
}
} | [
"func",
"(",
"cs",
"*",
"StreamManager",
")",
"LockProtectedEntry",
"(",
"e",
"*",
"Entry",
")",
"{",
"for",
"i",
":=",
"range",
"e",
".",
"Values",
"{",
"if",
"bool",
"(",
"e",
".",
"Values",
"[",
"i",
"]",
".",
"Value",
".",
"Protected",
")",
"... | // LockProtectedEntry locks an unprotected entry | [
"LockProtectedEntry",
"locks",
"an",
"unprotected",
"entry"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/crypto.go#L148-L157 |
17,837 | tobischo/gokeepasslib | decoder.go | Decode | func (d *Decoder) Decode(db *Database) error {
// Read header
db.Header = new(DBHeader)
if err := db.Header.readFrom(d.r); err != nil {
return err
}
// Calculate transformed key to decrypt and calculate HMAC
transformedKey, err := db.getTransformedKey()
if err != nil {
return err
}
// Read hashes and validate them (Kdbx v4)
if db.Header.IsKdbx4() {
db.Hashes = new(DBHashes)
if err := db.Hashes.readFrom(d.r); err != nil {
return err
}
if db.Options.ValidateHashes {
if err := db.Header.ValidateSha256(db.Hashes.Sha256); err != nil {
return err
}
hmacKey := buildHmacKey(db, transformedKey)
if err := db.Header.ValidateHmacSha256(hmacKey, db.Hashes.Hmac); err != nil {
return errors.New("Wrong password? HMAC-SHA256 of header mismatching")
}
}
}
// Decode raw content
rawContent, _ := ioutil.ReadAll(d.r)
if err := decodeRawContent(db, rawContent, transformedKey); err != nil {
return err
}
contentReader := bytes.NewReader(db.Content.RawData)
// Read InnerHeader (Kdbx v4)
if db.Header.IsKdbx4() {
db.Content.InnerHeader = new(InnerHeader)
if err := db.Content.InnerHeader.readFrom(contentReader); err != nil {
return err
}
}
// Decode xml
xmlDecoder := xml.NewDecoder(contentReader)
return xmlDecoder.Decode(db.Content)
} | go | func (d *Decoder) Decode(db *Database) error {
// Read header
db.Header = new(DBHeader)
if err := db.Header.readFrom(d.r); err != nil {
return err
}
// Calculate transformed key to decrypt and calculate HMAC
transformedKey, err := db.getTransformedKey()
if err != nil {
return err
}
// Read hashes and validate them (Kdbx v4)
if db.Header.IsKdbx4() {
db.Hashes = new(DBHashes)
if err := db.Hashes.readFrom(d.r); err != nil {
return err
}
if db.Options.ValidateHashes {
if err := db.Header.ValidateSha256(db.Hashes.Sha256); err != nil {
return err
}
hmacKey := buildHmacKey(db, transformedKey)
if err := db.Header.ValidateHmacSha256(hmacKey, db.Hashes.Hmac); err != nil {
return errors.New("Wrong password? HMAC-SHA256 of header mismatching")
}
}
}
// Decode raw content
rawContent, _ := ioutil.ReadAll(d.r)
if err := decodeRawContent(db, rawContent, transformedKey); err != nil {
return err
}
contentReader := bytes.NewReader(db.Content.RawData)
// Read InnerHeader (Kdbx v4)
if db.Header.IsKdbx4() {
db.Content.InnerHeader = new(InnerHeader)
if err := db.Content.InnerHeader.readFrom(contentReader); err != nil {
return err
}
}
// Decode xml
xmlDecoder := xml.NewDecoder(contentReader)
return xmlDecoder.Decode(db.Content)
} | [
"func",
"(",
"d",
"*",
"Decoder",
")",
"Decode",
"(",
"db",
"*",
"Database",
")",
"error",
"{",
"// Read header",
"db",
".",
"Header",
"=",
"new",
"(",
"DBHeader",
")",
"\n",
"if",
"err",
":=",
"db",
".",
"Header",
".",
"readFrom",
"(",
"d",
".",
... | // Decode populates given database with the data of Decoder reader | [
"Decode",
"populates",
"given",
"database",
"with",
"the",
"data",
"of",
"Decoder",
"reader"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/decoder.go#L24-L75 |
17,838 | tobischo/gokeepasslib | crypto/salsa.go | NewSalsaStream | func NewSalsaStream(key []byte) (*SalsaStream, error) {
hash := sha256.Sum256(key)
state := make([]uint32, 16)
state[1] = u8to32little(hash[:], 0)
state[2] = u8to32little(hash[:], 4)
state[3] = u8to32little(hash[:], 8)
state[4] = u8to32little(hash[:], 12)
state[11] = u8to32little(hash[:], 16)
state[12] = u8to32little(hash[:], 20)
state[13] = u8to32little(hash[:], 24)
state[14] = u8to32little(hash[:], 28)
state[0] = sigmaWords[0]
state[5] = sigmaWords[1]
state[10] = sigmaWords[2]
state[15] = sigmaWords[3]
state[6] = u8to32little(iv, 0)
state[7] = u8to32little(iv, 4)
state[8] = uint32(0)
state[9] = uint32(0)
s := SalsaStream{
State: state,
blockUsed: 64, // Ensure a fresh block is generated, the first time bytes are needed
currentBlock: make([]byte, 0),
}
return &s, nil
} | go | func NewSalsaStream(key []byte) (*SalsaStream, error) {
hash := sha256.Sum256(key)
state := make([]uint32, 16)
state[1] = u8to32little(hash[:], 0)
state[2] = u8to32little(hash[:], 4)
state[3] = u8to32little(hash[:], 8)
state[4] = u8to32little(hash[:], 12)
state[11] = u8to32little(hash[:], 16)
state[12] = u8to32little(hash[:], 20)
state[13] = u8to32little(hash[:], 24)
state[14] = u8to32little(hash[:], 28)
state[0] = sigmaWords[0]
state[5] = sigmaWords[1]
state[10] = sigmaWords[2]
state[15] = sigmaWords[3]
state[6] = u8to32little(iv, 0)
state[7] = u8to32little(iv, 4)
state[8] = uint32(0)
state[9] = uint32(0)
s := SalsaStream{
State: state,
blockUsed: 64, // Ensure a fresh block is generated, the first time bytes are needed
currentBlock: make([]byte, 0),
}
return &s, nil
} | [
"func",
"NewSalsaStream",
"(",
"key",
"[",
"]",
"byte",
")",
"(",
"*",
"SalsaStream",
",",
"error",
")",
"{",
"hash",
":=",
"sha256",
".",
"Sum256",
"(",
"key",
")",
"\n",
"state",
":=",
"make",
"(",
"[",
"]",
"uint32",
",",
"16",
")",
"\n\n",
"s... | // NewSalsaStream initialize a new SalsaStream interfaced with CryptoStream | [
"NewSalsaStream",
"initialize",
"a",
"new",
"SalsaStream",
"interfaced",
"with",
"CryptoStream"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/crypto/salsa.go#L25-L53 |
17,839 | tobischo/gokeepasslib | header.go | NewFileHeaders | func NewFileHeaders() *FileHeaders {
masterSeed := make([]byte, 32)
rand.Read(masterSeed)
transformSeed := make([]byte, 32)
rand.Read(transformSeed)
encryptionIV := make([]byte, 16)
rand.Read(encryptionIV)
protectedStreamKey := make([]byte, 32)
rand.Read(protectedStreamKey)
streamStartBytes := make([]byte, 32)
rand.Read(streamStartBytes)
return &FileHeaders{
CipherID: CipherAES,
CompressionFlags: GzipCompressionFlag,
MasterSeed: masterSeed,
TransformSeed: transformSeed,
TransformRounds: 6000,
EncryptionIV: encryptionIV,
ProtectedStreamKey: protectedStreamKey,
StreamStartBytes: streamStartBytes,
InnerRandomStreamID: SalsaStreamID,
}
} | go | func NewFileHeaders() *FileHeaders {
masterSeed := make([]byte, 32)
rand.Read(masterSeed)
transformSeed := make([]byte, 32)
rand.Read(transformSeed)
encryptionIV := make([]byte, 16)
rand.Read(encryptionIV)
protectedStreamKey := make([]byte, 32)
rand.Read(protectedStreamKey)
streamStartBytes := make([]byte, 32)
rand.Read(streamStartBytes)
return &FileHeaders{
CipherID: CipherAES,
CompressionFlags: GzipCompressionFlag,
MasterSeed: masterSeed,
TransformSeed: transformSeed,
TransformRounds: 6000,
EncryptionIV: encryptionIV,
ProtectedStreamKey: protectedStreamKey,
StreamStartBytes: streamStartBytes,
InnerRandomStreamID: SalsaStreamID,
}
} | [
"func",
"NewFileHeaders",
"(",
")",
"*",
"FileHeaders",
"{",
"masterSeed",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"32",
")",
"\n",
"rand",
".",
"Read",
"(",
"masterSeed",
")",
"\n\n",
"transformSeed",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"32"... | // NewFileHeaders creates a new FileHeaders with good defaults | [
"NewFileHeaders",
"creates",
"a",
"new",
"FileHeaders",
"with",
"good",
"defaults"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/header.go#L120-L147 |
17,840 | tobischo/gokeepasslib | header.go | readFrom | func (h *DBHeader) readFrom(r io.Reader) error {
// Save read data into a buffer that will be the RawData
buffer := bytes.NewBuffer([]byte{})
tR := io.TeeReader(r, buffer)
// Read signature
h.Signature = new(Signature)
if err := binary.Read(tR, binary.LittleEndian, h.Signature); err != nil {
return err
}
// Read file headers
h.FileHeaders = new(FileHeaders)
for {
var err error
if h.IsKdbx4() {
err = h.FileHeaders.readHeader4(tR)
} else {
err = h.FileHeaders.readHeader31(tR)
}
// Update RawData buffer
h.RawData = buffer.Bytes()
if err != nil {
if err == ErrEndOfHeaders {
break
}
return err
}
}
return nil
} | go | func (h *DBHeader) readFrom(r io.Reader) error {
// Save read data into a buffer that will be the RawData
buffer := bytes.NewBuffer([]byte{})
tR := io.TeeReader(r, buffer)
// Read signature
h.Signature = new(Signature)
if err := binary.Read(tR, binary.LittleEndian, h.Signature); err != nil {
return err
}
// Read file headers
h.FileHeaders = new(FileHeaders)
for {
var err error
if h.IsKdbx4() {
err = h.FileHeaders.readHeader4(tR)
} else {
err = h.FileHeaders.readHeader31(tR)
}
// Update RawData buffer
h.RawData = buffer.Bytes()
if err != nil {
if err == ErrEndOfHeaders {
break
}
return err
}
}
return nil
} | [
"func",
"(",
"h",
"*",
"DBHeader",
")",
"readFrom",
"(",
"r",
"io",
".",
"Reader",
")",
"error",
"{",
"// Save read data into a buffer that will be the RawData",
"buffer",
":=",
"bytes",
".",
"NewBuffer",
"(",
"[",
"]",
"byte",
"{",
"}",
")",
"\n",
"tR",
"... | // readFrom reads the header from an io.Reader | [
"readFrom",
"reads",
"the",
"header",
"from",
"an",
"io",
".",
"Reader"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/header.go#L150-L182 |
17,841 | tobischo/gokeepasslib | header.go | readHeader4 | func (fh *FileHeaders) readHeader4(r io.Reader) error {
var id uint8
var length uint32
var data []byte
if err := binary.Read(r, binary.LittleEndian, &id); err != nil {
return err
}
if err := binary.Read(r, binary.LittleEndian, &length); err != nil {
return err
}
data = make([]byte, length)
if err := binary.Read(r, binary.LittleEndian, &data); err != nil {
return err
}
return fh.readFileHeader(id, data)
} | go | func (fh *FileHeaders) readHeader4(r io.Reader) error {
var id uint8
var length uint32
var data []byte
if err := binary.Read(r, binary.LittleEndian, &id); err != nil {
return err
}
if err := binary.Read(r, binary.LittleEndian, &length); err != nil {
return err
}
data = make([]byte, length)
if err := binary.Read(r, binary.LittleEndian, &data); err != nil {
return err
}
return fh.readFileHeader(id, data)
} | [
"func",
"(",
"fh",
"*",
"FileHeaders",
")",
"readHeader4",
"(",
"r",
"io",
".",
"Reader",
")",
"error",
"{",
"var",
"id",
"uint8",
"\n",
"var",
"length",
"uint32",
"\n",
"var",
"data",
"[",
"]",
"byte",
"\n\n",
"if",
"err",
":=",
"binary",
".",
"Re... | // readHeader4 reads a header of a KDBX v4 database | [
"readHeader4",
"reads",
"a",
"header",
"of",
"a",
"KDBX",
"v4",
"database"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/header.go#L185-L202 |
17,842 | tobischo/gokeepasslib | header.go | readFileHeader | func (fh *FileHeaders) readFileHeader(id uint8, data []byte) error {
switch id {
case 0:
return ErrEndOfHeaders
case 1:
fh.Comment = data
case 2:
fh.CipherID = data
case 3:
fh.CompressionFlags = binary.LittleEndian.Uint32(data)
case 4:
fh.MasterSeed = data
case 5:
fh.TransformSeed = data
case 6:
fh.TransformRounds = binary.LittleEndian.Uint64(data)
case 7:
fh.EncryptionIV = data
case 8:
fh.ProtectedStreamKey = data
case 9:
fh.StreamStartBytes = data
case 10:
fh.InnerRandomStreamID = binary.LittleEndian.Uint32(data)
case 11:
fh.KdfParameters = new(KdfParameters)
return fh.KdfParameters.readKdfParameters(data)
case 12:
fh.PublicCustomData = new(VariantDictionary)
return fh.PublicCustomData.readVariantDictionary(data)
default:
return ErrUnknownHeaderID(id)
}
return nil
} | go | func (fh *FileHeaders) readFileHeader(id uint8, data []byte) error {
switch id {
case 0:
return ErrEndOfHeaders
case 1:
fh.Comment = data
case 2:
fh.CipherID = data
case 3:
fh.CompressionFlags = binary.LittleEndian.Uint32(data)
case 4:
fh.MasterSeed = data
case 5:
fh.TransformSeed = data
case 6:
fh.TransformRounds = binary.LittleEndian.Uint64(data)
case 7:
fh.EncryptionIV = data
case 8:
fh.ProtectedStreamKey = data
case 9:
fh.StreamStartBytes = data
case 10:
fh.InnerRandomStreamID = binary.LittleEndian.Uint32(data)
case 11:
fh.KdfParameters = new(KdfParameters)
return fh.KdfParameters.readKdfParameters(data)
case 12:
fh.PublicCustomData = new(VariantDictionary)
return fh.PublicCustomData.readVariantDictionary(data)
default:
return ErrUnknownHeaderID(id)
}
return nil
} | [
"func",
"(",
"fh",
"*",
"FileHeaders",
")",
"readFileHeader",
"(",
"id",
"uint8",
",",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"switch",
"id",
"{",
"case",
"0",
":",
"return",
"ErrEndOfHeaders",
"\n",
"case",
"1",
":",
"fh",
".",
"Comment",
"=",... | // readFileHeader reads a header value and puts it into the right variable | [
"readFileHeader",
"reads",
"a",
"header",
"value",
"and",
"puts",
"it",
"into",
"the",
"right",
"variable"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/header.go#L225-L259 |
17,843 | tobischo/gokeepasslib | header.go | readKdfParameters | func (k *KdfParameters) readKdfParameters(data []byte) error {
dict := new(VariantDictionary)
if err := dict.readVariantDictionary(data); err != nil {
return err
}
k.RawData = dict
for _, item := range dict.Items {
switch string(item.Name) {
case "$UUID":
k.UUID = item.Value
case "R":
k.Rounds = binary.LittleEndian.Uint64(item.Value)
case "S":
copy(k.Salt[:], item.Value[:32])
case "P":
k.Parallelism = binary.LittleEndian.Uint32(item.Value)
case "M":
k.Memory = binary.LittleEndian.Uint64(item.Value)
case "I":
k.Iterations = binary.LittleEndian.Uint64(item.Value)
case "V":
k.Version = binary.LittleEndian.Uint32(item.Value)
case "K":
k.SecretKey = item.Value
case "A":
k.AssocData = item.Value
default:
return ErrUnknownParameterID(string(item.Name))
}
}
return nil
} | go | func (k *KdfParameters) readKdfParameters(data []byte) error {
dict := new(VariantDictionary)
if err := dict.readVariantDictionary(data); err != nil {
return err
}
k.RawData = dict
for _, item := range dict.Items {
switch string(item.Name) {
case "$UUID":
k.UUID = item.Value
case "R":
k.Rounds = binary.LittleEndian.Uint64(item.Value)
case "S":
copy(k.Salt[:], item.Value[:32])
case "P":
k.Parallelism = binary.LittleEndian.Uint32(item.Value)
case "M":
k.Memory = binary.LittleEndian.Uint64(item.Value)
case "I":
k.Iterations = binary.LittleEndian.Uint64(item.Value)
case "V":
k.Version = binary.LittleEndian.Uint32(item.Value)
case "K":
k.SecretKey = item.Value
case "A":
k.AssocData = item.Value
default:
return ErrUnknownParameterID(string(item.Name))
}
}
return nil
} | [
"func",
"(",
"k",
"*",
"KdfParameters",
")",
"readKdfParameters",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"dict",
":=",
"new",
"(",
"VariantDictionary",
")",
"\n",
"if",
"err",
":=",
"dict",
".",
"readVariantDictionary",
"(",
"data",
")",
";",
... | // readKdfParameters reads a variant dictionary and puts values into KdfParameters | [
"readKdfParameters",
"reads",
"a",
"variant",
"dictionary",
"and",
"puts",
"values",
"into",
"KdfParameters"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/header.go#L262-L294 |
17,844 | tobischo/gokeepasslib | header.go | readVariantDictionary | func (vd *VariantDictionary) readVariantDictionary(data []byte) error {
r := bytes.NewReader(data)
if err := binary.Read(r, binary.LittleEndian, &vd.Version); err != nil {
return err
}
for {
vdi := new(VariantDictionaryItem)
if err := binary.Read(r, binary.LittleEndian, &vdi.Type); err != nil {
return err
}
if vdi.Type != 0x00 {
if err := binary.Read(r, binary.LittleEndian, &vdi.NameLength); err != nil {
return err
}
vdi.Name = make([]byte, vdi.NameLength)
if err := binary.Read(r, binary.LittleEndian, &vdi.Name); err != nil {
return err
}
if err := binary.Read(r, binary.LittleEndian, &vdi.ValueLength); err != nil {
return err
}
vdi.Value = make([]byte, vdi.ValueLength)
if err := binary.Read(r, binary.LittleEndian, &vdi.Value); err != nil {
return err
}
vd.Items = append(vd.Items, vdi)
} else {
break
}
}
return nil
} | go | func (vd *VariantDictionary) readVariantDictionary(data []byte) error {
r := bytes.NewReader(data)
if err := binary.Read(r, binary.LittleEndian, &vd.Version); err != nil {
return err
}
for {
vdi := new(VariantDictionaryItem)
if err := binary.Read(r, binary.LittleEndian, &vdi.Type); err != nil {
return err
}
if vdi.Type != 0x00 {
if err := binary.Read(r, binary.LittleEndian, &vdi.NameLength); err != nil {
return err
}
vdi.Name = make([]byte, vdi.NameLength)
if err := binary.Read(r, binary.LittleEndian, &vdi.Name); err != nil {
return err
}
if err := binary.Read(r, binary.LittleEndian, &vdi.ValueLength); err != nil {
return err
}
vdi.Value = make([]byte, vdi.ValueLength)
if err := binary.Read(r, binary.LittleEndian, &vdi.Value); err != nil {
return err
}
vd.Items = append(vd.Items, vdi)
} else {
break
}
}
return nil
} | [
"func",
"(",
"vd",
"*",
"VariantDictionary",
")",
"readVariantDictionary",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"r",
":=",
"bytes",
".",
"NewReader",
"(",
"data",
")",
"\n\n",
"if",
"err",
":=",
"binary",
".",
"Read",
"(",
"r",
",",
"bin... | // readVariantDictionary reads a variant dictionary | [
"readVariantDictionary",
"reads",
"a",
"variant",
"dictionary"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/header.go#L297-L333 |
17,845 | tobischo/gokeepasslib | header.go | writeTo | func (h *DBHeader) writeTo(w io.Writer) error {
var buffer bytes.Buffer
mw := io.MultiWriter(w, &buffer)
binary.Write(mw, binary.LittleEndian, h.Signature)
if h.IsKdbx4() {
h.FileHeaders.writeTo4(mw, &buffer)
} else {
h.FileHeaders.writeTo31(mw)
}
h.RawData = buffer.Bytes()
return nil
} | go | func (h *DBHeader) writeTo(w io.Writer) error {
var buffer bytes.Buffer
mw := io.MultiWriter(w, &buffer)
binary.Write(mw, binary.LittleEndian, h.Signature)
if h.IsKdbx4() {
h.FileHeaders.writeTo4(mw, &buffer)
} else {
h.FileHeaders.writeTo31(mw)
}
h.RawData = buffer.Bytes()
return nil
} | [
"func",
"(",
"h",
"*",
"DBHeader",
")",
"writeTo",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"var",
"buffer",
"bytes",
".",
"Buffer",
"\n",
"mw",
":=",
"io",
".",
"MultiWriter",
"(",
"w",
",",
"&",
"buffer",
")",
"\n\n",
"binary",
".",
"W... | // writeTo writes the header to the given io.Writer | [
"writeTo",
"writes",
"the",
"header",
"to",
"the",
"given",
"io",
".",
"Writer"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/header.go#L336-L351 |
17,846 | tobischo/gokeepasslib | header.go | writeTo4 | func (fh FileHeaders) writeTo4(w io.Writer, buf *bytes.Buffer) error {
compressionFlags := make([]byte, 4)
binary.LittleEndian.PutUint32(compressionFlags, fh.CompressionFlags)
if err := writeTo4Header(w, 1, fh.Comment); err != nil {
return err
}
if err := writeTo4Header(w, 2, fh.CipherID); err != nil {
return err
}
if err := writeTo4Header(w, 3, compressionFlags); err != nil {
return err
}
if err := writeTo4Header(w, 4, fh.MasterSeed); err != nil {
return err
}
if err := writeTo4Header(w, 7, fh.EncryptionIV); err != nil {
return err
}
if err := writeTo4VariantDictionary(w, 11, fh.KdfParameters.RawData); err != nil {
return err
}
if err := writeTo4VariantDictionary(w, 12, fh.PublicCustomData); err != nil {
return err
}
// End of header
return writeTo4Header(w, 0, []byte{0x0D, 0x0A, 0x0D, 0x0A})
} | go | func (fh FileHeaders) writeTo4(w io.Writer, buf *bytes.Buffer) error {
compressionFlags := make([]byte, 4)
binary.LittleEndian.PutUint32(compressionFlags, fh.CompressionFlags)
if err := writeTo4Header(w, 1, fh.Comment); err != nil {
return err
}
if err := writeTo4Header(w, 2, fh.CipherID); err != nil {
return err
}
if err := writeTo4Header(w, 3, compressionFlags); err != nil {
return err
}
if err := writeTo4Header(w, 4, fh.MasterSeed); err != nil {
return err
}
if err := writeTo4Header(w, 7, fh.EncryptionIV); err != nil {
return err
}
if err := writeTo4VariantDictionary(w, 11, fh.KdfParameters.RawData); err != nil {
return err
}
if err := writeTo4VariantDictionary(w, 12, fh.PublicCustomData); err != nil {
return err
}
// End of header
return writeTo4Header(w, 0, []byte{0x0D, 0x0A, 0x0D, 0x0A})
} | [
"func",
"(",
"fh",
"FileHeaders",
")",
"writeTo4",
"(",
"w",
"io",
".",
"Writer",
",",
"buf",
"*",
"bytes",
".",
"Buffer",
")",
"error",
"{",
"compressionFlags",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"4",
")",
"\n",
"binary",
".",
"LittleEndian",... | // writeTo4 writes a Kdbx v4 structured file header to the given io.Writer | [
"writeTo4",
"writes",
"a",
"Kdbx",
"v4",
"structured",
"file",
"header",
"to",
"the",
"given",
"io",
".",
"Writer"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/header.go#L354-L381 |
17,847 | tobischo/gokeepasslib | header.go | writeTo4Header | func writeTo4Header(w io.Writer, id uint8, data []byte) error {
if len(data) > 0 {
if err := binary.Write(w, binary.LittleEndian, id); err != nil {
return err
}
if err := binary.Write(w, binary.LittleEndian, uint32(len(data))); err != nil {
return err
}
if err := binary.Write(w, binary.LittleEndian, data); err != nil {
return err
}
}
return nil
} | go | func writeTo4Header(w io.Writer, id uint8, data []byte) error {
if len(data) > 0 {
if err := binary.Write(w, binary.LittleEndian, id); err != nil {
return err
}
if err := binary.Write(w, binary.LittleEndian, uint32(len(data))); err != nil {
return err
}
if err := binary.Write(w, binary.LittleEndian, data); err != nil {
return err
}
}
return nil
} | [
"func",
"writeTo4Header",
"(",
"w",
"io",
".",
"Writer",
",",
"id",
"uint8",
",",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"data",
")",
">",
"0",
"{",
"if",
"err",
":=",
"binary",
".",
"Write",
"(",
"w",
",",
"binary",
"."... | // writeTo4Header is an helper to write a file header with the correct Kdbx v4 structure to the given io.Writer | [
"writeTo4Header",
"is",
"an",
"helper",
"to",
"write",
"a",
"file",
"header",
"with",
"the",
"correct",
"Kdbx",
"v4",
"structure",
"to",
"the",
"given",
"io",
".",
"Writer"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/header.go#L384-L397 |
17,848 | tobischo/gokeepasslib | header.go | writeTo4VariantDictionary | func writeTo4VariantDictionary(w io.Writer, id uint8, data *VariantDictionary) error {
if data != nil {
var buffer bytes.Buffer
if err := binary.Write(&buffer, binary.LittleEndian, data.Version); err != nil {
return err
}
for _, item := range data.Items {
if err := binary.Write(&buffer, binary.LittleEndian, item.Type); err != nil {
return err
}
if err := binary.Write(&buffer, binary.LittleEndian, item.NameLength); err != nil {
return err
}
if err := binary.Write(&buffer, binary.LittleEndian, item.Name); err != nil {
return err
}
if err := binary.Write(&buffer, binary.LittleEndian, item.ValueLength); err != nil {
return err
}
if err := binary.Write(&buffer, binary.LittleEndian, item.Value); err != nil {
return err
}
}
if err := binary.Write(&buffer, binary.LittleEndian, []byte{0x00}); err != nil {
return err
}
// Write to original writer
if err := binary.Write(w, binary.LittleEndian, id); err != nil {
return err
}
if err := binary.Write(w, binary.LittleEndian, uint32(buffer.Len())); err != nil {
return err
}
if err := binary.Write(w, binary.LittleEndian, buffer.Bytes()); err != nil {
return err
}
}
return nil
} | go | func writeTo4VariantDictionary(w io.Writer, id uint8, data *VariantDictionary) error {
if data != nil {
var buffer bytes.Buffer
if err := binary.Write(&buffer, binary.LittleEndian, data.Version); err != nil {
return err
}
for _, item := range data.Items {
if err := binary.Write(&buffer, binary.LittleEndian, item.Type); err != nil {
return err
}
if err := binary.Write(&buffer, binary.LittleEndian, item.NameLength); err != nil {
return err
}
if err := binary.Write(&buffer, binary.LittleEndian, item.Name); err != nil {
return err
}
if err := binary.Write(&buffer, binary.LittleEndian, item.ValueLength); err != nil {
return err
}
if err := binary.Write(&buffer, binary.LittleEndian, item.Value); err != nil {
return err
}
}
if err := binary.Write(&buffer, binary.LittleEndian, []byte{0x00}); err != nil {
return err
}
// Write to original writer
if err := binary.Write(w, binary.LittleEndian, id); err != nil {
return err
}
if err := binary.Write(w, binary.LittleEndian, uint32(buffer.Len())); err != nil {
return err
}
if err := binary.Write(w, binary.LittleEndian, buffer.Bytes()); err != nil {
return err
}
}
return nil
} | [
"func",
"writeTo4VariantDictionary",
"(",
"w",
"io",
".",
"Writer",
",",
"id",
"uint8",
",",
"data",
"*",
"VariantDictionary",
")",
"error",
"{",
"if",
"data",
"!=",
"nil",
"{",
"var",
"buffer",
"bytes",
".",
"Buffer",
"\n",
"if",
"err",
":=",
"binary",
... | // writeTo31Header is an helper to write a variant dictionary to the given io.Writer | [
"writeTo31Header",
"is",
"an",
"helper",
"to",
"write",
"a",
"variant",
"dictionary",
"to",
"the",
"given",
"io",
".",
"Writer"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/header.go#L400-L439 |
17,849 | tobischo/gokeepasslib | header.go | writeTo31 | func (fh FileHeaders) writeTo31(w io.Writer) error {
compressionFlags := make([]byte, 4)
binary.LittleEndian.PutUint32(compressionFlags, fh.CompressionFlags)
transformRounds := make([]byte, 8)
binary.LittleEndian.PutUint64(transformRounds, fh.TransformRounds)
innerRandomStreamID := make([]byte, 4)
binary.LittleEndian.PutUint32(innerRandomStreamID, fh.InnerRandomStreamID)
if err := writeTo31Header(w, 1, fh.Comment); err != nil {
return err
}
if err := writeTo31Header(w, 2, fh.CipherID); err != nil {
return err
}
if err := writeTo31Header(w, 3, compressionFlags); err != nil {
return err
}
if err := writeTo31Header(w, 4, fh.MasterSeed); err != nil {
return err
}
if err := writeTo31Header(w, 5, fh.TransformSeed); err != nil {
return err
}
if err := writeTo31Header(w, 6, transformRounds); err != nil {
return err
}
if err := writeTo31Header(w, 7, fh.EncryptionIV); err != nil {
return err
}
if err := writeTo31Header(w, 8, fh.ProtectedStreamKey); err != nil {
return err
}
if err := writeTo31Header(w, 9, fh.StreamStartBytes); err != nil {
return err
}
if err := writeTo31Header(w, 10, innerRandomStreamID); err != nil {
return err
}
// End of header
return writeTo31Header(w, 0, []byte{0x0D, 0x0A, 0x0D, 0x0A})
} | go | func (fh FileHeaders) writeTo31(w io.Writer) error {
compressionFlags := make([]byte, 4)
binary.LittleEndian.PutUint32(compressionFlags, fh.CompressionFlags)
transformRounds := make([]byte, 8)
binary.LittleEndian.PutUint64(transformRounds, fh.TransformRounds)
innerRandomStreamID := make([]byte, 4)
binary.LittleEndian.PutUint32(innerRandomStreamID, fh.InnerRandomStreamID)
if err := writeTo31Header(w, 1, fh.Comment); err != nil {
return err
}
if err := writeTo31Header(w, 2, fh.CipherID); err != nil {
return err
}
if err := writeTo31Header(w, 3, compressionFlags); err != nil {
return err
}
if err := writeTo31Header(w, 4, fh.MasterSeed); err != nil {
return err
}
if err := writeTo31Header(w, 5, fh.TransformSeed); err != nil {
return err
}
if err := writeTo31Header(w, 6, transformRounds); err != nil {
return err
}
if err := writeTo31Header(w, 7, fh.EncryptionIV); err != nil {
return err
}
if err := writeTo31Header(w, 8, fh.ProtectedStreamKey); err != nil {
return err
}
if err := writeTo31Header(w, 9, fh.StreamStartBytes); err != nil {
return err
}
if err := writeTo31Header(w, 10, innerRandomStreamID); err != nil {
return err
}
// End of header
return writeTo31Header(w, 0, []byte{0x0D, 0x0A, 0x0D, 0x0A})
} | [
"func",
"(",
"fh",
"FileHeaders",
")",
"writeTo31",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"compressionFlags",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"4",
")",
"\n",
"binary",
".",
"LittleEndian",
".",
"PutUint32",
"(",
"compressionFlags",
... | // writeTo31 writes a Kdbx v3.1 structured file header to the given io.Writer | [
"writeTo31",
"writes",
"a",
"Kdbx",
"v3",
".",
"1",
"structured",
"file",
"header",
"to",
"the",
"given",
"io",
".",
"Writer"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/header.go#L442-L484 |
17,850 | tobischo/gokeepasslib | header.go | writeTo31Header | func writeTo31Header(w io.Writer, id uint8, data []byte) error {
if len(data) > 0 {
if err := binary.Write(w, binary.LittleEndian, id); err != nil {
return err
}
if err := binary.Write(w, binary.LittleEndian, uint16(len(data))); err != nil {
return err
}
if err := binary.Write(w, binary.LittleEndian, data); err != nil {
return err
}
}
return nil
} | go | func writeTo31Header(w io.Writer, id uint8, data []byte) error {
if len(data) > 0 {
if err := binary.Write(w, binary.LittleEndian, id); err != nil {
return err
}
if err := binary.Write(w, binary.LittleEndian, uint16(len(data))); err != nil {
return err
}
if err := binary.Write(w, binary.LittleEndian, data); err != nil {
return err
}
}
return nil
} | [
"func",
"writeTo31Header",
"(",
"w",
"io",
".",
"Writer",
",",
"id",
"uint8",
",",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"data",
")",
">",
"0",
"{",
"if",
"err",
":=",
"binary",
".",
"Write",
"(",
"w",
",",
"binary",
".... | // writeTo31Header is an helper to write a file header with the correct Kdbx v3.1 structure to the given io.Writer | [
"writeTo31Header",
"is",
"an",
"helper",
"to",
"write",
"a",
"file",
"header",
"with",
"the",
"correct",
"Kdbx",
"v3",
".",
"1",
"structure",
"to",
"the",
"given",
"io",
".",
"Writer"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/header.go#L487-L500 |
17,851 | tobischo/gokeepasslib | header.go | Get | func (vd *VariantDictionary) Get(key string) *VariantDictionaryItem {
for _, item := range vd.Items {
if string(item.Name) == key {
return item
}
}
return nil
} | go | func (vd *VariantDictionary) Get(key string) *VariantDictionaryItem {
for _, item := range vd.Items {
if string(item.Name) == key {
return item
}
}
return nil
} | [
"func",
"(",
"vd",
"*",
"VariantDictionary",
")",
"Get",
"(",
"key",
"string",
")",
"*",
"VariantDictionaryItem",
"{",
"for",
"_",
",",
"item",
":=",
"range",
"vd",
".",
"Items",
"{",
"if",
"string",
"(",
"item",
".",
"Name",
")",
"==",
"key",
"{",
... | // Get a VariantDictionaryItem via its key | [
"Get",
"a",
"VariantDictionaryItem",
"via",
"its",
"key"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/header.go#L503-L510 |
17,852 | tobischo/gokeepasslib | header.go | ValidateSha256 | func (h *DBHeader) ValidateSha256(hash [32]byte) error {
sha := h.GetSha256()
if !reflect.DeepEqual(sha, hash) {
return errors.New("Sha256 of header mismatching")
}
return nil
} | go | func (h *DBHeader) ValidateSha256(hash [32]byte) error {
sha := h.GetSha256()
if !reflect.DeepEqual(sha, hash) {
return errors.New("Sha256 of header mismatching")
}
return nil
} | [
"func",
"(",
"h",
"*",
"DBHeader",
")",
"ValidateSha256",
"(",
"hash",
"[",
"32",
"]",
"byte",
")",
"error",
"{",
"sha",
":=",
"h",
".",
"GetSha256",
"(",
")",
"\n",
"if",
"!",
"reflect",
".",
"DeepEqual",
"(",
"sha",
",",
"hash",
")",
"{",
"retu... | // ValidateSha256 validates the given hash with the Sha256 of the header | [
"ValidateSha256",
"validates",
"the",
"given",
"hash",
"with",
"the",
"Sha256",
"of",
"the",
"header"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/header.go#L523-L529 |
17,853 | tobischo/gokeepasslib | header.go | GetHmacSha256 | func (h *DBHeader) GetHmacSha256(hmacKey []byte) (ret [32]byte) {
hash := hmac.New(sha256.New, hmacKey)
hash.Write(h.RawData)
copy(ret[:32], hash.Sum(nil)[:32])
return
} | go | func (h *DBHeader) GetHmacSha256(hmacKey []byte) (ret [32]byte) {
hash := hmac.New(sha256.New, hmacKey)
hash.Write(h.RawData)
copy(ret[:32], hash.Sum(nil)[:32])
return
} | [
"func",
"(",
"h",
"*",
"DBHeader",
")",
"GetHmacSha256",
"(",
"hmacKey",
"[",
"]",
"byte",
")",
"(",
"ret",
"[",
"32",
"]",
"byte",
")",
"{",
"hash",
":=",
"hmac",
".",
"New",
"(",
"sha256",
".",
"New",
",",
"hmacKey",
")",
"\n",
"hash",
".",
"... | // GetHmacSha256 returns the HMAC-Sha256 hash of the header | [
"GetHmacSha256",
"returns",
"the",
"HMAC",
"-",
"Sha256",
"hash",
"of",
"the",
"header"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/header.go#L532-L537 |
17,854 | tobischo/gokeepasslib | header.go | ValidateHmacSha256 | func (h *DBHeader) ValidateHmacSha256(hmacKey []byte, hash [32]byte) error {
hmacSha := h.GetHmacSha256(hmacKey)
if !reflect.DeepEqual(hmacSha, hash) {
return errors.New("HMAC-Sha256 of header mismatching")
}
return nil
} | go | func (h *DBHeader) ValidateHmacSha256(hmacKey []byte, hash [32]byte) error {
hmacSha := h.GetHmacSha256(hmacKey)
if !reflect.DeepEqual(hmacSha, hash) {
return errors.New("HMAC-Sha256 of header mismatching")
}
return nil
} | [
"func",
"(",
"h",
"*",
"DBHeader",
")",
"ValidateHmacSha256",
"(",
"hmacKey",
"[",
"]",
"byte",
",",
"hash",
"[",
"32",
"]",
"byte",
")",
"error",
"{",
"hmacSha",
":=",
"h",
".",
"GetHmacSha256",
"(",
"hmacKey",
")",
"\n",
"if",
"!",
"reflect",
".",
... | // ValidateHmacSha256 validates the given hash with the HMAC-Sha256 of the header | [
"ValidateHmacSha256",
"validates",
"the",
"given",
"hash",
"with",
"the",
"HMAC",
"-",
"Sha256",
"of",
"the",
"header"
] | 8892e349f7674fa2214afba77de81fd6dfc44507 | https://github.com/tobischo/gokeepasslib/blob/8892e349f7674fa2214afba77de81fd6dfc44507/header.go#L540-L546 |
17,855 | restic/chunker | polynomials.go | Add | func (x Pol) Add(y Pol) Pol {
r := Pol(uint64(x) ^ uint64(y))
return r
} | go | func (x Pol) Add(y Pol) Pol {
r := Pol(uint64(x) ^ uint64(y))
return r
} | [
"func",
"(",
"x",
"Pol",
")",
"Add",
"(",
"y",
"Pol",
")",
"Pol",
"{",
"r",
":=",
"Pol",
"(",
"uint64",
"(",
"x",
")",
"^",
"uint64",
"(",
"y",
")",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // Add returns x+y. | [
"Add",
"returns",
"x",
"+",
"y",
"."
] | 43a9dae2133895ca2eadc5c187b4ce00e5b73cdc | https://github.com/restic/chunker/blob/43a9dae2133895ca2eadc5c187b4ce00e5b73cdc/polynomials.go#L16-L19 |
17,856 | restic/chunker | polynomials.go | Expand | func (x Pol) Expand() string {
if x == 0 {
return "0"
}
s := ""
for i := x.Deg(); i > 1; i-- {
if x&(1<<uint(i)) > 0 {
s += fmt.Sprintf("+x^%d", i)
}
}
if x&2 > 0 {
s += "+x"
}
if x&1 > 0 {
s += "+1"
}
return s[1:]
} | go | func (x Pol) Expand() string {
if x == 0 {
return "0"
}
s := ""
for i := x.Deg(); i > 1; i-- {
if x&(1<<uint(i)) > 0 {
s += fmt.Sprintf("+x^%d", i)
}
}
if x&2 > 0 {
s += "+x"
}
if x&1 > 0 {
s += "+1"
}
return s[1:]
} | [
"func",
"(",
"x",
"Pol",
")",
"Expand",
"(",
")",
"string",
"{",
"if",
"x",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"s",
":=",
"\"",
"\"",
"\n",
"for",
"i",
":=",
"x",
".",
"Deg",
"(",
")",
";",
"i",
">",
"1",
";",
"i",
... | // Expand returns the string representation of the polynomial x. | [
"Expand",
"returns",
"the",
"string",
"representation",
"of",
"the",
"polynomial",
"x",
"."
] | 43a9dae2133895ca2eadc5c187b4ce00e5b73cdc | https://github.com/restic/chunker/blob/43a9dae2133895ca2eadc5c187b4ce00e5b73cdc/polynomials.go#L109-L130 |
17,857 | restic/chunker | polynomials.go | GCD | func (x Pol) GCD(f Pol) Pol {
if f == 0 {
return x
}
if x == 0 {
return f
}
if x.Deg() < f.Deg() {
x, f = f, x
}
return f.GCD(x.Mod(f))
} | go | func (x Pol) GCD(f Pol) Pol {
if f == 0 {
return x
}
if x == 0 {
return f
}
if x.Deg() < f.Deg() {
x, f = f, x
}
return f.GCD(x.Mod(f))
} | [
"func",
"(",
"x",
"Pol",
")",
"GCD",
"(",
"f",
"Pol",
")",
"Pol",
"{",
"if",
"f",
"==",
"0",
"{",
"return",
"x",
"\n",
"}",
"\n\n",
"if",
"x",
"==",
"0",
"{",
"return",
"f",
"\n",
"}",
"\n\n",
"if",
"x",
".",
"Deg",
"(",
")",
"<",
"f",
... | // GCD computes the Greatest Common Divisor x and f. | [
"GCD",
"computes",
"the",
"Greatest",
"Common",
"Divisor",
"x",
"and",
"f",
"."
] | 43a9dae2133895ca2eadc5c187b4ce00e5b73cdc | https://github.com/restic/chunker/blob/43a9dae2133895ca2eadc5c187b4ce00e5b73cdc/polynomials.go#L221-L235 |
17,858 | restic/chunker | polynomials.go | Irreducible | func (x Pol) Irreducible() bool {
for i := 1; i <= x.Deg()/2; i++ {
if x.GCD(qp(uint(i), x)) != 1 {
return false
}
}
return true
} | go | func (x Pol) Irreducible() bool {
for i := 1; i <= x.Deg()/2; i++ {
if x.GCD(qp(uint(i), x)) != 1 {
return false
}
}
return true
} | [
"func",
"(",
"x",
"Pol",
")",
"Irreducible",
"(",
")",
"bool",
"{",
"for",
"i",
":=",
"1",
";",
"i",
"<=",
"x",
".",
"Deg",
"(",
")",
"/",
"2",
";",
"i",
"++",
"{",
"if",
"x",
".",
"GCD",
"(",
"qp",
"(",
"uint",
"(",
"i",
")",
",",
"x",... | // Irreducible returns true iff x is irreducible over F_2. This function
// uses Ben Or's reducibility test.
//
// For details see "Tests and Constructions of Irreducible Polynomials over
// Finite Fields". | [
"Irreducible",
"returns",
"true",
"iff",
"x",
"is",
"irreducible",
"over",
"F_2",
".",
"This",
"function",
"uses",
"Ben",
"Or",
"s",
"reducibility",
"test",
".",
"For",
"details",
"see",
"Tests",
"and",
"Constructions",
"of",
"Irreducible",
"Polynomials",
"ove... | 43a9dae2133895ca2eadc5c187b4ce00e5b73cdc | https://github.com/restic/chunker/blob/43a9dae2133895ca2eadc5c187b4ce00e5b73cdc/polynomials.go#L242-L250 |
17,859 | restic/chunker | polynomials.go | MarshalJSON | func (x Pol) MarshalJSON() ([]byte, error) {
buf := strconv.AppendUint([]byte{'"'}, uint64(x), 16)
buf = append(buf, '"')
return buf, nil
} | go | func (x Pol) MarshalJSON() ([]byte, error) {
buf := strconv.AppendUint([]byte{'"'}, uint64(x), 16)
buf = append(buf, '"')
return buf, nil
} | [
"func",
"(",
"x",
"Pol",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"buf",
":=",
"strconv",
".",
"AppendUint",
"(",
"[",
"]",
"byte",
"{",
"'\"'",
"}",
",",
"uint64",
"(",
"x",
")",
",",
"16",
")",
"\n",
"buf... | // MarshalJSON returns the JSON representation of the Pol. | [
"MarshalJSON",
"returns",
"the",
"JSON",
"representation",
"of",
"the",
"Pol",
"."
] | 43a9dae2133895ca2eadc5c187b4ce00e5b73cdc | https://github.com/restic/chunker/blob/43a9dae2133895ca2eadc5c187b4ce00e5b73cdc/polynomials.go#L292-L296 |
17,860 | restic/chunker | polynomials.go | UnmarshalJSON | func (x *Pol) UnmarshalJSON(data []byte) error {
if len(data) < 2 {
return errors.New("invalid string for polynomial")
}
n, err := strconv.ParseUint(string(data[1:len(data)-1]), 16, 64)
if err != nil {
return err
}
*x = Pol(n)
return nil
} | go | func (x *Pol) UnmarshalJSON(data []byte) error {
if len(data) < 2 {
return errors.New("invalid string for polynomial")
}
n, err := strconv.ParseUint(string(data[1:len(data)-1]), 16, 64)
if err != nil {
return err
}
*x = Pol(n)
return nil
} | [
"func",
"(",
"x",
"*",
"Pol",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"data",
")",
"<",
"2",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"n",
",",
"err",
":=",
... | // UnmarshalJSON parses a Pol from the JSON data. | [
"UnmarshalJSON",
"parses",
"a",
"Pol",
"from",
"the",
"JSON",
"data",
"."
] | 43a9dae2133895ca2eadc5c187b4ce00e5b73cdc | https://github.com/restic/chunker/blob/43a9dae2133895ca2eadc5c187b4ce00e5b73cdc/polynomials.go#L299-L310 |
17,861 | restic/chunker | chunker.go | New | func New(rd io.Reader, pol Pol) *Chunker {
return NewWithBoundaries(rd, pol, MinSize, MaxSize)
} | go | func New(rd io.Reader, pol Pol) *Chunker {
return NewWithBoundaries(rd, pol, MinSize, MaxSize)
} | [
"func",
"New",
"(",
"rd",
"io",
".",
"Reader",
",",
"pol",
"Pol",
")",
"*",
"Chunker",
"{",
"return",
"NewWithBoundaries",
"(",
"rd",
",",
"pol",
",",
"MinSize",
",",
"MaxSize",
")",
"\n",
"}"
] | // New returns a new Chunker based on polynomial p that reads from rd. | [
"New",
"returns",
"a",
"new",
"Chunker",
"based",
"on",
"polynomial",
"p",
"that",
"reads",
"from",
"rd",
"."
] | 43a9dae2133895ca2eadc5c187b4ce00e5b73cdc | https://github.com/restic/chunker/blob/43a9dae2133895ca2eadc5c187b4ce00e5b73cdc/chunker.go#L92-L94 |
17,862 | restic/chunker | chunker.go | NewWithBoundaries | func NewWithBoundaries(rd io.Reader, pol Pol, min, max uint) *Chunker {
c := &Chunker{
chunkerState: chunkerState{
buf: make([]byte, chunkerBufSize),
},
chunkerConfig: chunkerConfig{
pol: pol,
rd: rd,
MinSize: min,
MaxSize: max,
splitmask: (1 << 20) - 1, // aim to create chunks of 20 bits or about 1MiB on average.
},
}
c.reset()
return c
} | go | func NewWithBoundaries(rd io.Reader, pol Pol, min, max uint) *Chunker {
c := &Chunker{
chunkerState: chunkerState{
buf: make([]byte, chunkerBufSize),
},
chunkerConfig: chunkerConfig{
pol: pol,
rd: rd,
MinSize: min,
MaxSize: max,
splitmask: (1 << 20) - 1, // aim to create chunks of 20 bits or about 1MiB on average.
},
}
c.reset()
return c
} | [
"func",
"NewWithBoundaries",
"(",
"rd",
"io",
".",
"Reader",
",",
"pol",
"Pol",
",",
"min",
",",
"max",
"uint",
")",
"*",
"Chunker",
"{",
"c",
":=",
"&",
"Chunker",
"{",
"chunkerState",
":",
"chunkerState",
"{",
"buf",
":",
"make",
"(",
"[",
"]",
"... | // NewWithBoundaries returns a new Chunker based on polynomial p that reads from
// rd and custom min and max size boundaries. | [
"NewWithBoundaries",
"returns",
"a",
"new",
"Chunker",
"based",
"on",
"polynomial",
"p",
"that",
"reads",
"from",
"rd",
"and",
"custom",
"min",
"and",
"max",
"size",
"boundaries",
"."
] | 43a9dae2133895ca2eadc5c187b4ce00e5b73cdc | https://github.com/restic/chunker/blob/43a9dae2133895ca2eadc5c187b4ce00e5b73cdc/chunker.go#L98-L115 |
17,863 | restic/chunker | chunker.go | Reset | func (c *Chunker) Reset(rd io.Reader, pol Pol) {
c.ResetWithBoundaries(rd, pol, MinSize, MaxSize)
} | go | func (c *Chunker) Reset(rd io.Reader, pol Pol) {
c.ResetWithBoundaries(rd, pol, MinSize, MaxSize)
} | [
"func",
"(",
"c",
"*",
"Chunker",
")",
"Reset",
"(",
"rd",
"io",
".",
"Reader",
",",
"pol",
"Pol",
")",
"{",
"c",
".",
"ResetWithBoundaries",
"(",
"rd",
",",
"pol",
",",
"MinSize",
",",
"MaxSize",
")",
"\n",
"}"
] | // Reset reinitializes the chunker with a new reader and polynomial. | [
"Reset",
"reinitializes",
"the",
"chunker",
"with",
"a",
"new",
"reader",
"and",
"polynomial",
"."
] | 43a9dae2133895ca2eadc5c187b4ce00e5b73cdc | https://github.com/restic/chunker/blob/43a9dae2133895ca2eadc5c187b4ce00e5b73cdc/chunker.go#L118-L120 |
17,864 | restic/chunker | chunker.go | ResetWithBoundaries | func (c *Chunker) ResetWithBoundaries(rd io.Reader, pol Pol, min, max uint) {
*c = Chunker{
chunkerState: chunkerState{
buf: c.buf,
},
chunkerConfig: chunkerConfig{
pol: pol,
rd: rd,
MinSize: min,
MaxSize: max,
splitmask: (1 << 20) - 1,
},
}
c.reset()
} | go | func (c *Chunker) ResetWithBoundaries(rd io.Reader, pol Pol, min, max uint) {
*c = Chunker{
chunkerState: chunkerState{
buf: c.buf,
},
chunkerConfig: chunkerConfig{
pol: pol,
rd: rd,
MinSize: min,
MaxSize: max,
splitmask: (1 << 20) - 1,
},
}
c.reset()
} | [
"func",
"(",
"c",
"*",
"Chunker",
")",
"ResetWithBoundaries",
"(",
"rd",
"io",
".",
"Reader",
",",
"pol",
"Pol",
",",
"min",
",",
"max",
"uint",
")",
"{",
"*",
"c",
"=",
"Chunker",
"{",
"chunkerState",
":",
"chunkerState",
"{",
"buf",
":",
"c",
"."... | // ResetWithBoundaries reinitializes the chunker with a new reader, polynomial
// and custom min and max size boundaries. | [
"ResetWithBoundaries",
"reinitializes",
"the",
"chunker",
"with",
"a",
"new",
"reader",
"polynomial",
"and",
"custom",
"min",
"and",
"max",
"size",
"boundaries",
"."
] | 43a9dae2133895ca2eadc5c187b4ce00e5b73cdc | https://github.com/restic/chunker/blob/43a9dae2133895ca2eadc5c187b4ce00e5b73cdc/chunker.go#L124-L139 |
17,865 | restic/chunker | chunker.go | fillTables | func (c *Chunker) fillTables() {
// if polynomial hasn't been specified, do not compute anything for now
if c.pol == 0 {
return
}
c.tablesInitialized = true
// test if the tables are cached for this polynomial
cache.Lock()
defer cache.Unlock()
if t, ok := cache.entries[c.pol]; ok {
c.tables = t
return
}
// calculate table for sliding out bytes. The byte to slide out is used as
// the index for the table, the value contains the following:
// out_table[b] = Hash(b || 0 || ... || 0)
// \ windowsize-1 zero bytes /
// To slide out byte b_0 for window size w with known hash
// H := H(b_0 || ... || b_w), it is sufficient to add out_table[b_0]:
// H(b_0 || ... || b_w) + H(b_0 || 0 || ... || 0)
// = H(b_0 + b_0 || b_1 + 0 || ... || b_w + 0)
// = H( 0 || b_1 || ... || b_w)
//
// Afterwards a new byte can be shifted in.
for b := 0; b < 256; b++ {
var h Pol
h = appendByte(h, byte(b), c.pol)
for i := 0; i < windowSize-1; i++ {
h = appendByte(h, 0, c.pol)
}
c.tables.out[b] = h
}
// calculate table for reduction mod Polynomial
k := c.pol.Deg()
for b := 0; b < 256; b++ {
// mod_table[b] = A | B, where A = (b(x) * x^k mod pol) and B = b(x) * x^k
//
// The 8 bits above deg(Polynomial) determine what happens next and so
// these bits are used as a lookup to this table. The value is split in
// two parts: Part A contains the result of the modulus operation, part
// B is used to cancel out the 8 top bits so that one XOR operation is
// enough to reduce modulo Polynomial
c.tables.mod[b] = Pol(uint64(b)<<uint(k)).Mod(c.pol) | (Pol(b) << uint(k))
}
cache.entries[c.pol] = c.tables
} | go | func (c *Chunker) fillTables() {
// if polynomial hasn't been specified, do not compute anything for now
if c.pol == 0 {
return
}
c.tablesInitialized = true
// test if the tables are cached for this polynomial
cache.Lock()
defer cache.Unlock()
if t, ok := cache.entries[c.pol]; ok {
c.tables = t
return
}
// calculate table for sliding out bytes. The byte to slide out is used as
// the index for the table, the value contains the following:
// out_table[b] = Hash(b || 0 || ... || 0)
// \ windowsize-1 zero bytes /
// To slide out byte b_0 for window size w with known hash
// H := H(b_0 || ... || b_w), it is sufficient to add out_table[b_0]:
// H(b_0 || ... || b_w) + H(b_0 || 0 || ... || 0)
// = H(b_0 + b_0 || b_1 + 0 || ... || b_w + 0)
// = H( 0 || b_1 || ... || b_w)
//
// Afterwards a new byte can be shifted in.
for b := 0; b < 256; b++ {
var h Pol
h = appendByte(h, byte(b), c.pol)
for i := 0; i < windowSize-1; i++ {
h = appendByte(h, 0, c.pol)
}
c.tables.out[b] = h
}
// calculate table for reduction mod Polynomial
k := c.pol.Deg()
for b := 0; b < 256; b++ {
// mod_table[b] = A | B, where A = (b(x) * x^k mod pol) and B = b(x) * x^k
//
// The 8 bits above deg(Polynomial) determine what happens next and so
// these bits are used as a lookup to this table. The value is split in
// two parts: Part A contains the result of the modulus operation, part
// B is used to cancel out the 8 top bits so that one XOR operation is
// enough to reduce modulo Polynomial
c.tables.mod[b] = Pol(uint64(b)<<uint(k)).Mod(c.pol) | (Pol(b) << uint(k))
}
cache.entries[c.pol] = c.tables
} | [
"func",
"(",
"c",
"*",
"Chunker",
")",
"fillTables",
"(",
")",
"{",
"// if polynomial hasn't been specified, do not compute anything for now",
"if",
"c",
".",
"pol",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n\n",
"c",
".",
"tablesInitialized",
"=",
"true",
"\n\n",... | // fillTables calculates out_table and mod_table for optimization. This
// implementation uses a cache in the global variable cache. | [
"fillTables",
"calculates",
"out_table",
"and",
"mod_table",
"for",
"optimization",
".",
"This",
"implementation",
"uses",
"a",
"cache",
"in",
"the",
"global",
"variable",
"cache",
"."
] | 43a9dae2133895ca2eadc5c187b4ce00e5b73cdc | https://github.com/restic/chunker/blob/43a9dae2133895ca2eadc5c187b4ce00e5b73cdc/chunker.go#L162-L213 |
17,866 | dchest/stemmer | dutch/dutch.go | deleteESuffixPrecededByNonVowel | func deleteESuffixPrecededByNonVowel(s []rune, r1 int) ([]rune, bool) {
if i := len(s) - 1; i >= r1 && s[i] == 'e' && !isVowelAt(s, i-1) {
s = s[:i]
return s, true
}
return s, false
} | go | func deleteESuffixPrecededByNonVowel(s []rune, r1 int) ([]rune, bool) {
if i := len(s) - 1; i >= r1 && s[i] == 'e' && !isVowelAt(s, i-1) {
s = s[:i]
return s, true
}
return s, false
} | [
"func",
"deleteESuffixPrecededByNonVowel",
"(",
"s",
"[",
"]",
"rune",
",",
"r1",
"int",
")",
"(",
"[",
"]",
"rune",
",",
"bool",
")",
"{",
"if",
"i",
":=",
"len",
"(",
"s",
")",
"-",
"1",
";",
"i",
">=",
"r1",
"&&",
"s",
"[",
"i",
"]",
"==",... | // Delete suffix e if in R1 and preceded by a non-vowel | [
"Delete",
"suffix",
"e",
"if",
"in",
"R1",
"and",
"preceded",
"by",
"a",
"non",
"-",
"vowel"
] | 66719a20c4b5d119ff43ef41aab03265a3d644a7 | https://github.com/dchest/stemmer/blob/66719a20c4b5d119ff43ef41aab03265a3d644a7/dutch/dutch.go#L102-L108 |
17,867 | steveyen/gkvlite | collection.go | Get | func (t *Collection) Get(key []byte) (val []byte, err error) {
i, err := t.GetItem(key, true)
if err != nil {
return nil, err
}
if i != nil {
return i.Val, nil
}
return nil, nil
} | go | func (t *Collection) Get(key []byte) (val []byte, err error) {
i, err := t.GetItem(key, true)
if err != nil {
return nil, err
}
if i != nil {
return i.Val, nil
}
return nil, nil
} | [
"func",
"(",
"t",
"*",
"Collection",
")",
"Get",
"(",
"key",
"[",
"]",
"byte",
")",
"(",
"val",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"i",
",",
"err",
":=",
"t",
".",
"GetItem",
"(",
"key",
",",
"true",
")",
"\n",
"if",
"err",
"!... | // Retrieve a value by its key. Returns nil if the item is not in the
// collection. The returned value should be treated as immutable. | [
"Retrieve",
"a",
"value",
"by",
"its",
"key",
".",
"Returns",
"nil",
"if",
"the",
"item",
"is",
"not",
"in",
"the",
"collection",
".",
"The",
"returned",
"value",
"should",
"be",
"treated",
"as",
"immutable",
"."
] | 5b47ed6d7458f12bd18b0883b197f3e889ab9ad0 | https://github.com/steveyen/gkvlite/blob/5b47ed6d7458f12bd18b0883b197f3e889ab9ad0/collection.go#L109-L118 |
17,868 | steveyen/gkvlite | collection.go | Set | func (t *Collection) Set(key []byte, val []byte) error {
return t.SetItem(&Item{Key: key, Val: val, Priority: rand.Int31()})
} | go | func (t *Collection) Set(key []byte, val []byte) error {
return t.SetItem(&Item{Key: key, Val: val, Priority: rand.Int31()})
} | [
"func",
"(",
"t",
"*",
"Collection",
")",
"Set",
"(",
"key",
"[",
"]",
"byte",
",",
"val",
"[",
"]",
"byte",
")",
"error",
"{",
"return",
"t",
".",
"SetItem",
"(",
"&",
"Item",
"{",
"Key",
":",
"key",
",",
"Val",
":",
"val",
",",
"Priority",
... | // Replace or insert an item of a given key. | [
"Replace",
"or",
"insert",
"an",
"item",
"of",
"a",
"given",
"key",
"."
] | 5b47ed6d7458f12bd18b0883b197f3e889ab9ad0 | https://github.com/steveyen/gkvlite/blob/5b47ed6d7458f12bd18b0883b197f3e889ab9ad0/collection.go#L160-L162 |
17,869 | steveyen/gkvlite | collection.go | Delete | func (t *Collection) Delete(key []byte) (wasDeleted bool, err error) {
if t.store.readOnly {
return false, errors.New("store is read only")
}
rnl := t.rootAddRef()
defer t.rootDecRef(rnl)
root := rnl.root
i, err := t.GetItem(key, false)
if err != nil || i == nil {
return false, err
}
t.store.ItemDecRef(t, i)
left, middle, right, err := t.store.split(t, root, key, &rnl.reclaimMark)
if err != nil {
return false, err
}
defer t.freeNodeLoc(left)
defer t.freeNodeLoc(right)
defer t.freeNodeLoc(middle)
if middle.isEmpty() {
return false, fmt.Errorf("concurrent delete, key: %v", key)
}
r, err := t.store.join(t, left, right, &rnl.reclaimMark)
if err != nil {
return false, err
}
rnlNew := t.mkRootNodeLoc(r)
// Can't reclaim immediately due to readers.
rnlNew.reclaimLater[0] = t.reclaimMarkUpdate(left,
&rnl.reclaimMark, &rnlNew.reclaimMark)
rnlNew.reclaimLater[1] = t.reclaimMarkUpdate(right,
&rnl.reclaimMark, &rnlNew.reclaimMark)
rnlNew.reclaimLater[2] = t.reclaimMarkUpdate(middle,
&rnl.reclaimMark, &rnlNew.reclaimMark)
t.markReclaimable(rnlNew.reclaimLater[2], &rnlNew.reclaimMark)
if !t.rootCAS(rnl, rnlNew) {
return false, errors.New("concurrent mutation attempted")
}
t.rootDecRef(rnl)
return true, nil
} | go | func (t *Collection) Delete(key []byte) (wasDeleted bool, err error) {
if t.store.readOnly {
return false, errors.New("store is read only")
}
rnl := t.rootAddRef()
defer t.rootDecRef(rnl)
root := rnl.root
i, err := t.GetItem(key, false)
if err != nil || i == nil {
return false, err
}
t.store.ItemDecRef(t, i)
left, middle, right, err := t.store.split(t, root, key, &rnl.reclaimMark)
if err != nil {
return false, err
}
defer t.freeNodeLoc(left)
defer t.freeNodeLoc(right)
defer t.freeNodeLoc(middle)
if middle.isEmpty() {
return false, fmt.Errorf("concurrent delete, key: %v", key)
}
r, err := t.store.join(t, left, right, &rnl.reclaimMark)
if err != nil {
return false, err
}
rnlNew := t.mkRootNodeLoc(r)
// Can't reclaim immediately due to readers.
rnlNew.reclaimLater[0] = t.reclaimMarkUpdate(left,
&rnl.reclaimMark, &rnlNew.reclaimMark)
rnlNew.reclaimLater[1] = t.reclaimMarkUpdate(right,
&rnl.reclaimMark, &rnlNew.reclaimMark)
rnlNew.reclaimLater[2] = t.reclaimMarkUpdate(middle,
&rnl.reclaimMark, &rnlNew.reclaimMark)
t.markReclaimable(rnlNew.reclaimLater[2], &rnlNew.reclaimMark)
if !t.rootCAS(rnl, rnlNew) {
return false, errors.New("concurrent mutation attempted")
}
t.rootDecRef(rnl)
return true, nil
} | [
"func",
"(",
"t",
"*",
"Collection",
")",
"Delete",
"(",
"key",
"[",
"]",
"byte",
")",
"(",
"wasDeleted",
"bool",
",",
"err",
"error",
")",
"{",
"if",
"t",
".",
"store",
".",
"readOnly",
"{",
"return",
"false",
",",
"errors",
".",
"New",
"(",
"\"... | // Deletes an item of a given key. | [
"Deletes",
"an",
"item",
"of",
"a",
"given",
"key",
"."
] | 5b47ed6d7458f12bd18b0883b197f3e889ab9ad0 | https://github.com/steveyen/gkvlite/blob/5b47ed6d7458f12bd18b0883b197f3e889ab9ad0/collection.go#L165-L205 |
17,870 | steveyen/gkvlite | collection.go | MinItem | func (t *Collection) MinItem(withValue bool) (*Item, error) {
return t.store.walk(t, withValue,
func(n *node) (*nodeLoc, bool) { return &n.left, true })
} | go | func (t *Collection) MinItem(withValue bool) (*Item, error) {
return t.store.walk(t, withValue,
func(n *node) (*nodeLoc, bool) { return &n.left, true })
} | [
"func",
"(",
"t",
"*",
"Collection",
")",
"MinItem",
"(",
"withValue",
"bool",
")",
"(",
"*",
"Item",
",",
"error",
")",
"{",
"return",
"t",
".",
"store",
".",
"walk",
"(",
"t",
",",
"withValue",
",",
"func",
"(",
"n",
"*",
"node",
")",
"(",
"*... | // Retrieves the item with the "smallest" key.
// The returned item should be treated as immutable. | [
"Retrieves",
"the",
"item",
"with",
"the",
"smallest",
"key",
".",
"The",
"returned",
"item",
"should",
"be",
"treated",
"as",
"immutable",
"."
] | 5b47ed6d7458f12bd18b0883b197f3e889ab9ad0 | https://github.com/steveyen/gkvlite/blob/5b47ed6d7458f12bd18b0883b197f3e889ab9ad0/collection.go#L209-L212 |
17,871 | steveyen/gkvlite | collection.go | MaxItem | func (t *Collection) MaxItem(withValue bool) (*Item, error) {
return t.store.walk(t, withValue,
func(n *node) (*nodeLoc, bool) { return &n.right, true })
} | go | func (t *Collection) MaxItem(withValue bool) (*Item, error) {
return t.store.walk(t, withValue,
func(n *node) (*nodeLoc, bool) { return &n.right, true })
} | [
"func",
"(",
"t",
"*",
"Collection",
")",
"MaxItem",
"(",
"withValue",
"bool",
")",
"(",
"*",
"Item",
",",
"error",
")",
"{",
"return",
"t",
".",
"store",
".",
"walk",
"(",
"t",
",",
"withValue",
",",
"func",
"(",
"n",
"*",
"node",
")",
"(",
"*... | // Retrieves the item with the "largest" key.
// The returned item should be treated as immutable. | [
"Retrieves",
"the",
"item",
"with",
"the",
"largest",
"key",
".",
"The",
"returned",
"item",
"should",
"be",
"treated",
"as",
"immutable",
"."
] | 5b47ed6d7458f12bd18b0883b197f3e889ab9ad0 | https://github.com/steveyen/gkvlite/blob/5b47ed6d7458f12bd18b0883b197f3e889ab9ad0/collection.go#L216-L219 |
17,872 | steveyen/gkvlite | collection.go | VisitItemsAscend | func (t *Collection) VisitItemsAscend(target []byte, withValue bool, v ItemVisitor) error {
return t.VisitItemsAscendEx(target, withValue,
func(i *Item, depth uint64) bool { return v(i) })
} | go | func (t *Collection) VisitItemsAscend(target []byte, withValue bool, v ItemVisitor) error {
return t.VisitItemsAscendEx(target, withValue,
func(i *Item, depth uint64) bool { return v(i) })
} | [
"func",
"(",
"t",
"*",
"Collection",
")",
"VisitItemsAscend",
"(",
"target",
"[",
"]",
"byte",
",",
"withValue",
"bool",
",",
"v",
"ItemVisitor",
")",
"error",
"{",
"return",
"t",
".",
"VisitItemsAscendEx",
"(",
"target",
",",
"withValue",
",",
"func",
"... | // Visit items greater-than-or-equal to the target key in ascending order. | [
"Visit",
"items",
"greater",
"-",
"than",
"-",
"or",
"-",
"equal",
"to",
"the",
"target",
"key",
"in",
"ascending",
"order",
"."
] | 5b47ed6d7458f12bd18b0883b197f3e889ab9ad0 | https://github.com/steveyen/gkvlite/blob/5b47ed6d7458f12bd18b0883b197f3e889ab9ad0/collection.go#L256-L259 |
17,873 | steveyen/gkvlite | collection.go | VisitItemsDescend | func (t *Collection) VisitItemsDescend(target []byte, withValue bool, v ItemVisitor) error {
return t.VisitItemsDescendEx(target, withValue,
func(i *Item, depth uint64) bool { return v(i) })
} | go | func (t *Collection) VisitItemsDescend(target []byte, withValue bool, v ItemVisitor) error {
return t.VisitItemsDescendEx(target, withValue,
func(i *Item, depth uint64) bool { return v(i) })
} | [
"func",
"(",
"t",
"*",
"Collection",
")",
"VisitItemsDescend",
"(",
"target",
"[",
"]",
"byte",
",",
"withValue",
"bool",
",",
"v",
"ItemVisitor",
")",
"error",
"{",
"return",
"t",
".",
"VisitItemsDescendEx",
"(",
"target",
",",
"withValue",
",",
"func",
... | // Visit items less-than the target key in descending order. | [
"Visit",
"items",
"less",
"-",
"than",
"the",
"target",
"key",
"in",
"descending",
"order",
"."
] | 5b47ed6d7458f12bd18b0883b197f3e889ab9ad0 | https://github.com/steveyen/gkvlite/blob/5b47ed6d7458f12bd18b0883b197f3e889ab9ad0/collection.go#L262-L265 |
17,874 | steveyen/gkvlite | collection.go | VisitItemsAscendEx | func (t *Collection) VisitItemsAscendEx(target []byte, withValue bool,
visitor ItemVisitorEx) error {
rnl := t.rootAddRef()
defer t.rootDecRef(rnl)
var prevVisitItem *Item
var errCheckedVisitor error
checkedVisitor := func(i *Item, depth uint64) bool {
if prevVisitItem != nil && t.compare(prevVisitItem.Key, i.Key) > 0 {
errCheckedVisitor = fmt.Errorf("corrupted / out-of-order index"+
", key: %s vs %s, coll: %p, collName: %s, store: %p, storeFile: %v",
string(prevVisitItem.Key), string(i.Key), t, t.name, t.store, t.store.file)
return false
}
prevVisitItem = i
return visitor(i, depth)
}
_, err := t.store.visitNodes(t, rnl.root,
target, withValue, checkedVisitor, 0, ascendChoice)
if errCheckedVisitor != nil {
return errCheckedVisitor
}
return err
} | go | func (t *Collection) VisitItemsAscendEx(target []byte, withValue bool,
visitor ItemVisitorEx) error {
rnl := t.rootAddRef()
defer t.rootDecRef(rnl)
var prevVisitItem *Item
var errCheckedVisitor error
checkedVisitor := func(i *Item, depth uint64) bool {
if prevVisitItem != nil && t.compare(prevVisitItem.Key, i.Key) > 0 {
errCheckedVisitor = fmt.Errorf("corrupted / out-of-order index"+
", key: %s vs %s, coll: %p, collName: %s, store: %p, storeFile: %v",
string(prevVisitItem.Key), string(i.Key), t, t.name, t.store, t.store.file)
return false
}
prevVisitItem = i
return visitor(i, depth)
}
_, err := t.store.visitNodes(t, rnl.root,
target, withValue, checkedVisitor, 0, ascendChoice)
if errCheckedVisitor != nil {
return errCheckedVisitor
}
return err
} | [
"func",
"(",
"t",
"*",
"Collection",
")",
"VisitItemsAscendEx",
"(",
"target",
"[",
"]",
"byte",
",",
"withValue",
"bool",
",",
"visitor",
"ItemVisitorEx",
")",
"error",
"{",
"rnl",
":=",
"t",
".",
"rootAddRef",
"(",
")",
"\n",
"defer",
"t",
".",
"root... | // Visit items greater-than-or-equal to the target key in ascending order; with depth info. | [
"Visit",
"items",
"greater",
"-",
"than",
"-",
"or",
"-",
"equal",
"to",
"the",
"target",
"key",
"in",
"ascending",
"order",
";",
"with",
"depth",
"info",
"."
] | 5b47ed6d7458f12bd18b0883b197f3e889ab9ad0 | https://github.com/steveyen/gkvlite/blob/5b47ed6d7458f12bd18b0883b197f3e889ab9ad0/collection.go#L268-L293 |
17,875 | steveyen/gkvlite | collection.go | VisitItemsDescendEx | func (t *Collection) VisitItemsDescendEx(target []byte, withValue bool,
visitor ItemVisitorEx) error {
rnl := t.rootAddRef()
defer t.rootDecRef(rnl)
_, err := t.store.visitNodes(t, rnl.root,
target, withValue, visitor, 0, descendChoice)
return err
} | go | func (t *Collection) VisitItemsDescendEx(target []byte, withValue bool,
visitor ItemVisitorEx) error {
rnl := t.rootAddRef()
defer t.rootDecRef(rnl)
_, err := t.store.visitNodes(t, rnl.root,
target, withValue, visitor, 0, descendChoice)
return err
} | [
"func",
"(",
"t",
"*",
"Collection",
")",
"VisitItemsDescendEx",
"(",
"target",
"[",
"]",
"byte",
",",
"withValue",
"bool",
",",
"visitor",
"ItemVisitorEx",
")",
"error",
"{",
"rnl",
":=",
"t",
".",
"rootAddRef",
"(",
")",
"\n",
"defer",
"t",
".",
"roo... | // Visit items less-than the target key in descending order; with depth info. | [
"Visit",
"items",
"less",
"-",
"than",
"the",
"target",
"key",
"in",
"descending",
"order",
";",
"with",
"depth",
"info",
"."
] | 5b47ed6d7458f12bd18b0883b197f3e889ab9ad0 | https://github.com/steveyen/gkvlite/blob/5b47ed6d7458f12bd18b0883b197f3e889ab9ad0/collection.go#L296-L304 |
17,876 | steveyen/gkvlite | collection.go | GetTotals | func (t *Collection) GetTotals() (numItems uint64, numBytes uint64, err error) {
rnl := t.rootAddRef()
defer t.rootDecRef(rnl)
n := rnl.root
nNode, err := n.read(t.store)
if err != nil || n.isEmpty() || nNode == nil {
return 0, 0, err
}
return nNode.numNodes, nNode.numBytes, nil
} | go | func (t *Collection) GetTotals() (numItems uint64, numBytes uint64, err error) {
rnl := t.rootAddRef()
defer t.rootDecRef(rnl)
n := rnl.root
nNode, err := n.read(t.store)
if err != nil || n.isEmpty() || nNode == nil {
return 0, 0, err
}
return nNode.numNodes, nNode.numBytes, nil
} | [
"func",
"(",
"t",
"*",
"Collection",
")",
"GetTotals",
"(",
")",
"(",
"numItems",
"uint64",
",",
"numBytes",
"uint64",
",",
"err",
"error",
")",
"{",
"rnl",
":=",
"t",
".",
"rootAddRef",
"(",
")",
"\n",
"defer",
"t",
".",
"rootDecRef",
"(",
"rnl",
... | // Returns total number of items and total key bytes plus value bytes. | [
"Returns",
"total",
"number",
"of",
"items",
"and",
"total",
"key",
"bytes",
"plus",
"value",
"bytes",
"."
] | 5b47ed6d7458f12bd18b0883b197f3e889ab9ad0 | https://github.com/steveyen/gkvlite/blob/5b47ed6d7458f12bd18b0883b197f3e889ab9ad0/collection.go#L315-L324 |
17,877 | steveyen/gkvlite | collection.go | UnmarshalJSON | func (t *Collection) UnmarshalJSON(d []byte) error {
p := ploc{}
if err := json.Unmarshal(d, &p); err != nil {
return err
}
if t.rootLock == nil {
t.rootLock = &sync.Mutex{}
}
nloc := t.mkNodeLoc(nil)
nloc.loc = unsafe.Pointer(&p)
if !t.rootCAS(nil, t.mkRootNodeLoc(nloc)) {
return errors.New("concurrent mutation during UnmarshalJSON().")
}
return nil
} | go | func (t *Collection) UnmarshalJSON(d []byte) error {
p := ploc{}
if err := json.Unmarshal(d, &p); err != nil {
return err
}
if t.rootLock == nil {
t.rootLock = &sync.Mutex{}
}
nloc := t.mkNodeLoc(nil)
nloc.loc = unsafe.Pointer(&p)
if !t.rootCAS(nil, t.mkRootNodeLoc(nloc)) {
return errors.New("concurrent mutation during UnmarshalJSON().")
}
return nil
} | [
"func",
"(",
"t",
"*",
"Collection",
")",
"UnmarshalJSON",
"(",
"d",
"[",
"]",
"byte",
")",
"error",
"{",
"p",
":=",
"ploc",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"d",
",",
"&",
"p",
")",
";",
"err",
"!=",
"nil",
"... | // Unmarshals JSON representation of root node file location. | [
"Unmarshals",
"JSON",
"representation",
"of",
"root",
"node",
"file",
"location",
"."
] | 5b47ed6d7458f12bd18b0883b197f3e889ab9ad0 | https://github.com/steveyen/gkvlite/blob/5b47ed6d7458f12bd18b0883b197f3e889ab9ad0/collection.go#L343-L357 |
17,878 | steveyen/gkvlite | item.go | NumBytes | func (i *Item) NumBytes(c *Collection) int {
return len(i.Key) + i.NumValBytes(c)
} | go | func (i *Item) NumBytes(c *Collection) int {
return len(i.Key) + i.NumValBytes(c)
} | [
"func",
"(",
"i",
"*",
"Item",
")",
"NumBytes",
"(",
"c",
"*",
"Collection",
")",
"int",
"{",
"return",
"len",
"(",
"i",
".",
"Key",
")",
"+",
"i",
".",
"NumValBytes",
"(",
"c",
")",
"\n",
"}"
] | // Number of Key bytes plus number of Val bytes. | [
"Number",
"of",
"Key",
"bytes",
"plus",
"number",
"of",
"Val",
"bytes",
"."
] | 5b47ed6d7458f12bd18b0883b197f3e889ab9ad0 | https://github.com/steveyen/gkvlite/blob/5b47ed6d7458f12bd18b0883b197f3e889ab9ad0/item.go#L27-L29 |
17,879 | steveyen/gkvlite | tools/slab/slab.go | readBufChain | func readBufChain(arena *slab.Arena, maxBufSize int, r io.ReaderAt, offset int64,
valLength uint32) ([]byte, error) {
n := int(valLength)
if n > maxBufSize {
n = maxBufSize
}
b := arena.Alloc(n)
_, err := r.ReadAt(b, offset)
if err != nil {
arena.DecRef(b)
return nil, err
}
remaining := valLength - uint32(n)
if remaining > 0 {
next, err := readBufChain(arena, maxBufSize, r, offset + int64(n), remaining)
if err != nil {
arena.DecRef(b)
return nil, err
}
arena.SetNext(b, next)
}
return b, nil
} | go | func readBufChain(arena *slab.Arena, maxBufSize int, r io.ReaderAt, offset int64,
valLength uint32) ([]byte, error) {
n := int(valLength)
if n > maxBufSize {
n = maxBufSize
}
b := arena.Alloc(n)
_, err := r.ReadAt(b, offset)
if err != nil {
arena.DecRef(b)
return nil, err
}
remaining := valLength - uint32(n)
if remaining > 0 {
next, err := readBufChain(arena, maxBufSize, r, offset + int64(n), remaining)
if err != nil {
arena.DecRef(b)
return nil, err
}
arena.SetNext(b, next)
}
return b, nil
} | [
"func",
"readBufChain",
"(",
"arena",
"*",
"slab",
".",
"Arena",
",",
"maxBufSize",
"int",
",",
"r",
"io",
".",
"ReaderAt",
",",
"offset",
"int64",
",",
"valLength",
"uint32",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"n",
":=",
"int",
"(... | // Helper function to read a contiguous byte sequence, splitting
// it up into chained buf's of maxBufSize. The last buf in the
// chain can have length <= maxBufSize. | [
"Helper",
"function",
"to",
"read",
"a",
"contiguous",
"byte",
"sequence",
"splitting",
"it",
"up",
"into",
"chained",
"buf",
"s",
"of",
"maxBufSize",
".",
"The",
"last",
"buf",
"in",
"the",
"chain",
"can",
"have",
"length",
"<",
"=",
"maxBufSize",
"."
] | 5b47ed6d7458f12bd18b0883b197f3e889ab9ad0 | https://github.com/steveyen/gkvlite/blob/5b47ed6d7458f12bd18b0883b197f3e889ab9ad0/tools/slab/slab.go#L73-L95 |
17,880 | steveyen/gkvlite | store.go | GetCollection | func (s *Store) GetCollection(name string) *Collection {
coll := *(*map[string]*Collection)(atomic.LoadPointer(&s.coll))
return coll[name]
} | go | func (s *Store) GetCollection(name string) *Collection {
coll := *(*map[string]*Collection)(atomic.LoadPointer(&s.coll))
return coll[name]
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"GetCollection",
"(",
"name",
"string",
")",
"*",
"Collection",
"{",
"coll",
":=",
"*",
"(",
"*",
"map",
"[",
"string",
"]",
"*",
"Collection",
")",
"(",
"atomic",
".",
"LoadPointer",
"(",
"&",
"s",
".",
"coll",... | // Retrieves a named Collection. | [
"Retrieves",
"a",
"named",
"Collection",
"."
] | 5b47ed6d7458f12bd18b0883b197f3e889ab9ad0 | https://github.com/steveyen/gkvlite/blob/5b47ed6d7458f12bd18b0883b197f3e889ab9ad0/store.go#L151-L154 |
17,881 | steveyen/gkvlite | store.go | Stats | func (s *Store) Stats(out map[string]uint64) {
out["fileSize"] = uint64(atomic.LoadInt64(&s.size))
out["nodeAllocs"] = atomic.LoadUint64(&s.nodeAllocs)
} | go | func (s *Store) Stats(out map[string]uint64) {
out["fileSize"] = uint64(atomic.LoadInt64(&s.size))
out["nodeAllocs"] = atomic.LoadUint64(&s.nodeAllocs)
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"Stats",
"(",
"out",
"map",
"[",
"string",
"]",
"uint64",
")",
"{",
"out",
"[",
"\"",
"\"",
"]",
"=",
"uint64",
"(",
"atomic",
".",
"LoadInt64",
"(",
"&",
"s",
".",
"size",
")",
")",
"\n",
"out",
"[",
"\""... | // Updates the provided map with statistics. | [
"Updates",
"the",
"provided",
"map",
"with",
"statistics",
"."
] | 5b47ed6d7458f12bd18b0883b197f3e889ab9ad0 | https://github.com/steveyen/gkvlite/blob/5b47ed6d7458f12bd18b0883b197f3e889ab9ad0/store.go#L344-L347 |
17,882 | cocoonlife/goalsa | alsa.go | Close | func (d *device) Close() {
if d.h != nil {
C.snd_pcm_drain(d.h)
C.snd_pcm_close(d.h)
d.h = nil
}
runtime.SetFinalizer(d, nil)
} | go | func (d *device) Close() {
if d.h != nil {
C.snd_pcm_drain(d.h)
C.snd_pcm_close(d.h)
d.h = nil
}
runtime.SetFinalizer(d, nil)
} | [
"func",
"(",
"d",
"*",
"device",
")",
"Close",
"(",
")",
"{",
"if",
"d",
".",
"h",
"!=",
"nil",
"{",
"C",
".",
"snd_pcm_drain",
"(",
"d",
".",
"h",
")",
"\n",
"C",
".",
"snd_pcm_close",
"(",
"d",
".",
"h",
")",
"\n",
"d",
".",
"h",
"=",
"... | // Close closes a device and frees the resources associated with it. | [
"Close",
"closes",
"a",
"device",
"and",
"frees",
"the",
"resources",
"associated",
"with",
"it",
"."
] | b711ae6f3eff1a4f0cc4edfe321ab171027f85d4 | https://github.com/cocoonlife/goalsa/blob/b711ae6f3eff1a4f0cc4edfe321ab171027f85d4/alsa.go#L159-L166 |
17,883 | cocoonlife/goalsa | alsa.go | NewCaptureDevice | func NewCaptureDevice(deviceName string, channels int, format Format, rate int, bufferParams BufferParams) (c *CaptureDevice, err error) {
c = new(CaptureDevice)
err = c.createDevice(deviceName, channels, format, rate, false, bufferParams)
if err != nil {
return nil, err
}
return c, nil
} | go | func NewCaptureDevice(deviceName string, channels int, format Format, rate int, bufferParams BufferParams) (c *CaptureDevice, err error) {
c = new(CaptureDevice)
err = c.createDevice(deviceName, channels, format, rate, false, bufferParams)
if err != nil {
return nil, err
}
return c, nil
} | [
"func",
"NewCaptureDevice",
"(",
"deviceName",
"string",
",",
"channels",
"int",
",",
"format",
"Format",
",",
"rate",
"int",
",",
"bufferParams",
"BufferParams",
")",
"(",
"c",
"*",
"CaptureDevice",
",",
"err",
"error",
")",
"{",
"c",
"=",
"new",
"(",
"... | // NewCaptureDevice creates a new CaptureDevice object. | [
"NewCaptureDevice",
"creates",
"a",
"new",
"CaptureDevice",
"object",
"."
] | b711ae6f3eff1a4f0cc4edfe321ab171027f85d4 | https://github.com/cocoonlife/goalsa/blob/b711ae6f3eff1a4f0cc4edfe321ab171027f85d4/alsa.go#L188-L195 |
17,884 | cocoonlife/goalsa | alsa.go | NewPlaybackDevice | func NewPlaybackDevice(deviceName string, channels int, format Format, rate int, bufferParams BufferParams) (p *PlaybackDevice, err error) {
p = new(PlaybackDevice)
err = p.createDevice(deviceName, channels, format, rate, true, bufferParams)
if err != nil {
return nil, err
}
return p, nil
} | go | func NewPlaybackDevice(deviceName string, channels int, format Format, rate int, bufferParams BufferParams) (p *PlaybackDevice, err error) {
p = new(PlaybackDevice)
err = p.createDevice(deviceName, channels, format, rate, true, bufferParams)
if err != nil {
return nil, err
}
return p, nil
} | [
"func",
"NewPlaybackDevice",
"(",
"deviceName",
"string",
",",
"channels",
"int",
",",
"format",
"Format",
",",
"rate",
"int",
",",
"bufferParams",
"BufferParams",
")",
"(",
"p",
"*",
"PlaybackDevice",
",",
"err",
"error",
")",
"{",
"p",
"=",
"new",
"(",
... | // NewPlaybackDevice creates a new PlaybackDevice object. | [
"NewPlaybackDevice",
"creates",
"a",
"new",
"PlaybackDevice",
"object",
"."
] | b711ae6f3eff1a4f0cc4edfe321ab171027f85d4 | https://github.com/cocoonlife/goalsa/blob/b711ae6f3eff1a4f0cc4edfe321ab171027f85d4/alsa.go#L252-L259 |
17,885 | cocoonlife/goalsa | alsa.go | Write | func (p *PlaybackDevice) Write(buffer interface{}) (samples int, err error) {
bufferType := reflect.TypeOf(buffer)
if !(bufferType.Kind() == reflect.Array ||
bufferType.Kind() == reflect.Slice) {
return 0, errors.New("Write requires an array type")
}
sizeError := errors.New("Write requires a matching sample size")
switch bufferType.Elem().Kind() {
case reflect.Int8:
if p.formatSampleSize() != 1 {
return 0, sizeError
}
case reflect.Int16:
if p.formatSampleSize() != 2 {
return 0, sizeError
}
case reflect.Int32, reflect.Float32:
if p.formatSampleSize() != 4 {
return 0, sizeError
}
case reflect.Float64:
if p.formatSampleSize() != 8 {
return 0, sizeError
}
default:
return 0, errors.New("Write does not support this format")
}
val := reflect.ValueOf(buffer)
length := val.Len()
sliceData := val.Slice(0, length)
var frames = C.snd_pcm_uframes_t(length / p.Channels)
bufPtr := unsafe.Pointer(sliceData.Index(0).Addr().Pointer())
ret := C.snd_pcm_writei(p.h, bufPtr, frames)
if ret == -C.EPIPE {
C.snd_pcm_prepare(p.h)
return 0, ErrUnderrun
} else if ret < 0 {
return 0, createError("write error", C.int(ret))
}
samples = int(ret) * p.Channels
return
} | go | func (p *PlaybackDevice) Write(buffer interface{}) (samples int, err error) {
bufferType := reflect.TypeOf(buffer)
if !(bufferType.Kind() == reflect.Array ||
bufferType.Kind() == reflect.Slice) {
return 0, errors.New("Write requires an array type")
}
sizeError := errors.New("Write requires a matching sample size")
switch bufferType.Elem().Kind() {
case reflect.Int8:
if p.formatSampleSize() != 1 {
return 0, sizeError
}
case reflect.Int16:
if p.formatSampleSize() != 2 {
return 0, sizeError
}
case reflect.Int32, reflect.Float32:
if p.formatSampleSize() != 4 {
return 0, sizeError
}
case reflect.Float64:
if p.formatSampleSize() != 8 {
return 0, sizeError
}
default:
return 0, errors.New("Write does not support this format")
}
val := reflect.ValueOf(buffer)
length := val.Len()
sliceData := val.Slice(0, length)
var frames = C.snd_pcm_uframes_t(length / p.Channels)
bufPtr := unsafe.Pointer(sliceData.Index(0).Addr().Pointer())
ret := C.snd_pcm_writei(p.h, bufPtr, frames)
if ret == -C.EPIPE {
C.snd_pcm_prepare(p.h)
return 0, ErrUnderrun
} else if ret < 0 {
return 0, createError("write error", C.int(ret))
}
samples = int(ret) * p.Channels
return
} | [
"func",
"(",
"p",
"*",
"PlaybackDevice",
")",
"Write",
"(",
"buffer",
"interface",
"{",
"}",
")",
"(",
"samples",
"int",
",",
"err",
"error",
")",
"{",
"bufferType",
":=",
"reflect",
".",
"TypeOf",
"(",
"buffer",
")",
"\n",
"if",
"!",
"(",
"bufferTyp... | // Write writes a buffer of data to a playback device. | [
"Write",
"writes",
"a",
"buffer",
"of",
"data",
"to",
"a",
"playback",
"device",
"."
] | b711ae6f3eff1a4f0cc4edfe321ab171027f85d4 | https://github.com/cocoonlife/goalsa/blob/b711ae6f3eff1a4f0cc4edfe321ab171027f85d4/alsa.go#L262-L307 |
17,886 | go-ozzo/ozzo-log | filter.go | Init | func (t *Filter) Init() {
t.catNames = make(map[string]bool, 0)
t.catPrefixes = make([]string, 0)
for _, cat := range t.Categories {
if strings.HasSuffix(cat, "*") {
t.catPrefixes = append(t.catPrefixes, cat[:len(cat)-1])
} else {
t.catNames[cat] = true
}
}
} | go | func (t *Filter) Init() {
t.catNames = make(map[string]bool, 0)
t.catPrefixes = make([]string, 0)
for _, cat := range t.Categories {
if strings.HasSuffix(cat, "*") {
t.catPrefixes = append(t.catPrefixes, cat[:len(cat)-1])
} else {
t.catNames[cat] = true
}
}
} | [
"func",
"(",
"t",
"*",
"Filter",
")",
"Init",
"(",
")",
"{",
"t",
".",
"catNames",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
",",
"0",
")",
"\n",
"t",
".",
"catPrefixes",
"=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
")",
"\n",
... | // Init initializes the filter.
// Init must be called before Allow is called. | [
"Init",
"initializes",
"the",
"filter",
".",
"Init",
"must",
"be",
"called",
"before",
"Allow",
"is",
"called",
"."
] | 610cdd147d9aff9523eed107898d2e87ee5336aa | https://github.com/go-ozzo/ozzo-log/blob/610cdd147d9aff9523eed107898d2e87ee5336aa/filter.go#L22-L32 |
17,887 | go-ozzo/ozzo-log | filter.go | Allow | func (t *Filter) Allow(e *Entry) bool {
if e == nil {
return true
}
if e.Level > t.MaxLevel {
return false
}
if t.catNames[e.Category] {
return true
}
for _, cat := range t.catPrefixes {
if strings.HasPrefix(e.Category, cat) {
return true
}
}
return len(t.catNames) == 0 && len(t.catPrefixes) == 0
} | go | func (t *Filter) Allow(e *Entry) bool {
if e == nil {
return true
}
if e.Level > t.MaxLevel {
return false
}
if t.catNames[e.Category] {
return true
}
for _, cat := range t.catPrefixes {
if strings.HasPrefix(e.Category, cat) {
return true
}
}
return len(t.catNames) == 0 && len(t.catPrefixes) == 0
} | [
"func",
"(",
"t",
"*",
"Filter",
")",
"Allow",
"(",
"e",
"*",
"Entry",
")",
"bool",
"{",
"if",
"e",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"e",
".",
"Level",
">",
"t",
".",
"MaxLevel",
"{",
"return",
"false",
"\n",
"}",
"\... | // Allow checks if a message meets the severity level and category requirements. | [
"Allow",
"checks",
"if",
"a",
"message",
"meets",
"the",
"severity",
"level",
"and",
"category",
"requirements",
"."
] | 610cdd147d9aff9523eed107898d2e87ee5336aa | https://github.com/go-ozzo/ozzo-log/blob/610cdd147d9aff9523eed107898d2e87ee5336aa/filter.go#L35-L51 |
17,888 | go-ozzo/ozzo-log | file.go | Open | func (t *FileTarget) Open(errWriter io.Writer) error {
t.Filter.Init()
if t.FileName == "" {
return errors.New("FileTarget.FileName must be set")
}
if t.Rotate {
if t.BackupCount < 0 {
return errors.New("FileTarget.BackupCount must be no less than 0")
}
if t.MaxBytes <= 0 {
return errors.New("FileTarget.MaxBytes must be no less than 0")
}
}
fd, err := os.OpenFile(t.FileName, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0660)
if err != nil {
return fmt.Errorf("FileTarget was unable to create a log file: %v", err)
}
t.fd = fd
t.errWriter = errWriter
return nil
} | go | func (t *FileTarget) Open(errWriter io.Writer) error {
t.Filter.Init()
if t.FileName == "" {
return errors.New("FileTarget.FileName must be set")
}
if t.Rotate {
if t.BackupCount < 0 {
return errors.New("FileTarget.BackupCount must be no less than 0")
}
if t.MaxBytes <= 0 {
return errors.New("FileTarget.MaxBytes must be no less than 0")
}
}
fd, err := os.OpenFile(t.FileName, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0660)
if err != nil {
return fmt.Errorf("FileTarget was unable to create a log file: %v", err)
}
t.fd = fd
t.errWriter = errWriter
return nil
} | [
"func",
"(",
"t",
"*",
"FileTarget",
")",
"Open",
"(",
"errWriter",
"io",
".",
"Writer",
")",
"error",
"{",
"t",
".",
"Filter",
".",
"Init",
"(",
")",
"\n",
"if",
"t",
".",
"FileName",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
... | // Open prepares FileTarget for processing log messages. | [
"Open",
"prepares",
"FileTarget",
"for",
"processing",
"log",
"messages",
"."
] | 610cdd147d9aff9523eed107898d2e87ee5336aa | https://github.com/go-ozzo/ozzo-log/blob/610cdd147d9aff9523eed107898d2e87ee5336aa/file.go#L51-L73 |
17,889 | go-ozzo/ozzo-log | file.go | Process | func (t *FileTarget) Process(e *Entry) {
if e == nil {
t.fd.Close()
t.close <- true
return
}
if t.fd != nil && t.Allow(e) {
if t.Rotate {
t.rotate(int64(len(e.String()) + 1))
}
n, err := t.fd.Write([]byte(e.String() + "\n"))
t.currentBytes += int64(n)
if err != nil {
fmt.Fprintf(t.errWriter, "FileTarge write error: %v\n", err)
}
}
} | go | func (t *FileTarget) Process(e *Entry) {
if e == nil {
t.fd.Close()
t.close <- true
return
}
if t.fd != nil && t.Allow(e) {
if t.Rotate {
t.rotate(int64(len(e.String()) + 1))
}
n, err := t.fd.Write([]byte(e.String() + "\n"))
t.currentBytes += int64(n)
if err != nil {
fmt.Fprintf(t.errWriter, "FileTarge write error: %v\n", err)
}
}
} | [
"func",
"(",
"t",
"*",
"FileTarget",
")",
"Process",
"(",
"e",
"*",
"Entry",
")",
"{",
"if",
"e",
"==",
"nil",
"{",
"t",
".",
"fd",
".",
"Close",
"(",
")",
"\n",
"t",
".",
"close",
"<-",
"true",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"t",
"... | // Process saves an allowed log message into the log file. | [
"Process",
"saves",
"an",
"allowed",
"log",
"message",
"into",
"the",
"log",
"file",
"."
] | 610cdd147d9aff9523eed107898d2e87ee5336aa | https://github.com/go-ozzo/ozzo-log/blob/610cdd147d9aff9523eed107898d2e87ee5336aa/file.go#L76-L92 |
17,890 | go-ozzo/ozzo-log | network.go | Open | func (t *NetworkTarget) Open(errWriter io.Writer) error {
t.Filter.Init()
if t.BufferSize < 0 {
return errors.New("NetworkTarget.BufferSize must be no less than 0")
}
if t.Network == "" {
return errors.New("NetworkTarget.Network must be specified")
}
if t.Address == "" {
return errors.New("NetworkTarget.Address must be specified")
}
t.entries = make(chan *Entry, t.BufferSize)
t.conn = nil
if t.Persistent {
if err := t.connect(); err != nil {
return err
}
}
go t.sendMessages(errWriter)
return nil
} | go | func (t *NetworkTarget) Open(errWriter io.Writer) error {
t.Filter.Init()
if t.BufferSize < 0 {
return errors.New("NetworkTarget.BufferSize must be no less than 0")
}
if t.Network == "" {
return errors.New("NetworkTarget.Network must be specified")
}
if t.Address == "" {
return errors.New("NetworkTarget.Address must be specified")
}
t.entries = make(chan *Entry, t.BufferSize)
t.conn = nil
if t.Persistent {
if err := t.connect(); err != nil {
return err
}
}
go t.sendMessages(errWriter)
return nil
} | [
"func",
"(",
"t",
"*",
"NetworkTarget",
")",
"Open",
"(",
"errWriter",
"io",
".",
"Writer",
")",
"error",
"{",
"t",
".",
"Filter",
".",
"Init",
"(",
")",
"\n\n",
"if",
"t",
".",
"BufferSize",
"<",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\... | // Open prepares NetworkTarget for processing log messages. | [
"Open",
"prepares",
"NetworkTarget",
"for",
"processing",
"log",
"messages",
"."
] | 610cdd147d9aff9523eed107898d2e87ee5336aa | https://github.com/go-ozzo/ozzo-log/blob/610cdd147d9aff9523eed107898d2e87ee5336aa/network.go#L54-L79 |
17,891 | go-ozzo/ozzo-log | network.go | Process | func (t *NetworkTarget) Process(e *Entry) {
if t.Allow(e) {
select {
case t.entries <- e:
default:
}
}
} | go | func (t *NetworkTarget) Process(e *Entry) {
if t.Allow(e) {
select {
case t.entries <- e:
default:
}
}
} | [
"func",
"(",
"t",
"*",
"NetworkTarget",
")",
"Process",
"(",
"e",
"*",
"Entry",
")",
"{",
"if",
"t",
".",
"Allow",
"(",
"e",
")",
"{",
"select",
"{",
"case",
"t",
".",
"entries",
"<-",
"e",
":",
"default",
":",
"}",
"\n",
"}",
"\n",
"}"
] | // Process puts filtered log messages into a channel for sending over network. | [
"Process",
"puts",
"filtered",
"log",
"messages",
"into",
"a",
"channel",
"for",
"sending",
"over",
"network",
"."
] | 610cdd147d9aff9523eed107898d2e87ee5336aa | https://github.com/go-ozzo/ozzo-log/blob/610cdd147d9aff9523eed107898d2e87ee5336aa/network.go#L82-L89 |
17,892 | go-ozzo/ozzo-log | console.go | Open | func (t *ConsoleTarget) Open(io.Writer) error {
t.Filter.Init()
if t.Writer == nil {
return errors.New("ConsoleTarget.Writer cannot be nil")
}
if runtime.GOOS == "windows" {
t.ColorMode = false
}
return nil
} | go | func (t *ConsoleTarget) Open(io.Writer) error {
t.Filter.Init()
if t.Writer == nil {
return errors.New("ConsoleTarget.Writer cannot be nil")
}
if runtime.GOOS == "windows" {
t.ColorMode = false
}
return nil
} | [
"func",
"(",
"t",
"*",
"ConsoleTarget",
")",
"Open",
"(",
"io",
".",
"Writer",
")",
"error",
"{",
"t",
".",
"Filter",
".",
"Init",
"(",
")",
"\n",
"if",
"t",
".",
"Writer",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",... | // Open prepares ConsoleTarget for processing log messages. | [
"Open",
"prepares",
"ConsoleTarget",
"for",
"processing",
"log",
"messages",
"."
] | 610cdd147d9aff9523eed107898d2e87ee5336aa | https://github.com/go-ozzo/ozzo-log/blob/610cdd147d9aff9523eed107898d2e87ee5336aa/console.go#L55-L64 |
17,893 | go-ozzo/ozzo-log | console.go | Process | func (t *ConsoleTarget) Process(e *Entry) {
if e == nil {
t.close <- true
return
}
if !t.Allow(e) {
return
}
msg := e.String()
if t.ColorMode {
brush, ok := brushes[e.Level]
if ok {
msg = brush(msg)
}
}
fmt.Fprintln(t.Writer, msg)
} | go | func (t *ConsoleTarget) Process(e *Entry) {
if e == nil {
t.close <- true
return
}
if !t.Allow(e) {
return
}
msg := e.String()
if t.ColorMode {
brush, ok := brushes[e.Level]
if ok {
msg = brush(msg)
}
}
fmt.Fprintln(t.Writer, msg)
} | [
"func",
"(",
"t",
"*",
"ConsoleTarget",
")",
"Process",
"(",
"e",
"*",
"Entry",
")",
"{",
"if",
"e",
"==",
"nil",
"{",
"t",
".",
"close",
"<-",
"true",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"!",
"t",
".",
"Allow",
"(",
"e",
")",
"{",
"return... | // Process writes a log message using Writer. | [
"Process",
"writes",
"a",
"log",
"message",
"using",
"Writer",
"."
] | 610cdd147d9aff9523eed107898d2e87ee5336aa | https://github.com/go-ozzo/ozzo-log/blob/610cdd147d9aff9523eed107898d2e87ee5336aa/console.go#L67-L83 |
17,894 | go-ozzo/ozzo-log | logger.go | String | func (l Level) String() string {
if name, ok := LevelNames[l]; ok {
return name
}
return "Unknown"
} | go | func (l Level) String() string {
if name, ok := LevelNames[l]; ok {
return name
}
return "Unknown"
} | [
"func",
"(",
"l",
"Level",
")",
"String",
"(",
")",
"string",
"{",
"if",
"name",
",",
"ok",
":=",
"LevelNames",
"[",
"l",
"]",
";",
"ok",
"{",
"return",
"name",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // String returns the string representation of the log level | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"the",
"log",
"level"
] | 610cdd147d9aff9523eed107898d2e87ee5336aa | https://github.com/go-ozzo/ozzo-log/blob/610cdd147d9aff9523eed107898d2e87ee5336aa/logger.go#L48-L53 |
17,895 | go-ozzo/ozzo-log | logger.go | GetLogger | func (l *Logger) GetLogger(category string, formatter ...Formatter) *Logger {
if len(formatter) > 0 {
return &Logger{l.coreLogger, category, formatter[0]}
}
return &Logger{l.coreLogger, category, l.Formatter}
} | go | func (l *Logger) GetLogger(category string, formatter ...Formatter) *Logger {
if len(formatter) > 0 {
return &Logger{l.coreLogger, category, formatter[0]}
}
return &Logger{l.coreLogger, category, l.Formatter}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"GetLogger",
"(",
"category",
"string",
",",
"formatter",
"...",
"Formatter",
")",
"*",
"Logger",
"{",
"if",
"len",
"(",
"formatter",
")",
">",
"0",
"{",
"return",
"&",
"Logger",
"{",
"l",
".",
"coreLogger",
",",... | // GetLogger creates a logger with the specified category and log formatter.
// Messages logged through this logger will carry the same category name.
// The formatter, if not specified, will inherit from the calling logger.
// It will be used to format all messages logged through this logger. | [
"GetLogger",
"creates",
"a",
"logger",
"with",
"the",
"specified",
"category",
"and",
"log",
"formatter",
".",
"Messages",
"logged",
"through",
"this",
"logger",
"will",
"carry",
"the",
"same",
"category",
"name",
".",
"The",
"formatter",
"if",
"not",
"specifi... | 610cdd147d9aff9523eed107898d2e87ee5336aa | https://github.com/go-ozzo/ozzo-log/blob/610cdd147d9aff9523eed107898d2e87ee5336aa/logger.go#L128-L133 |
17,896 | go-ozzo/ozzo-log | logger.go | Log | func (l *Logger) Log(level Level, format string, a ...interface{}) {
if level > l.MaxLevel || !l.open {
return
}
message := format
if len(a) > 0 {
message = fmt.Sprintf(format, a...)
}
entry := &Entry{
Category: l.Category,
Level: level,
Message: message,
Time: time.Now(),
}
if l.CallStackDepth > 0 {
entry.CallStack = GetCallStack(3, l.CallStackDepth, l.CallStackFilter)
}
entry.FormattedMessage = l.Formatter(l, entry)
l.entries <- entry
} | go | func (l *Logger) Log(level Level, format string, a ...interface{}) {
if level > l.MaxLevel || !l.open {
return
}
message := format
if len(a) > 0 {
message = fmt.Sprintf(format, a...)
}
entry := &Entry{
Category: l.Category,
Level: level,
Message: message,
Time: time.Now(),
}
if l.CallStackDepth > 0 {
entry.CallStack = GetCallStack(3, l.CallStackDepth, l.CallStackFilter)
}
entry.FormattedMessage = l.Formatter(l, entry)
l.entries <- entry
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Log",
"(",
"level",
"Level",
",",
"format",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"level",
">",
"l",
".",
"MaxLevel",
"||",
"!",
"l",
".",
"open",
"{",
"return",
"\n",
"}",
"\n"... | // Log logs a message of a specified severity level. | [
"Log",
"logs",
"a",
"message",
"of",
"a",
"specified",
"severity",
"level",
"."
] | 610cdd147d9aff9523eed107898d2e87ee5336aa | https://github.com/go-ozzo/ozzo-log/blob/610cdd147d9aff9523eed107898d2e87ee5336aa/logger.go#L186-L205 |
17,897 | go-ozzo/ozzo-log | logger.go | Open | func (l *coreLogger) Open() error {
l.lock.Lock()
defer l.lock.Unlock()
if l.open {
return nil
}
if l.ErrorWriter == nil {
return errors.New("Logger.ErrorWriter must be set.")
}
if l.BufferSize < 0 {
return errors.New("Logger.BufferSize must be no less than 0.")
}
if l.CallStackDepth < 0 {
return errors.New("Logger.CallStackDepth must be no less than 0.")
}
l.entries = make(chan *Entry, l.BufferSize)
var targets []Target
for _, target := range l.Targets {
if err := target.Open(l.ErrorWriter); err != nil {
fmt.Fprintf(l.ErrorWriter, "Failed to open target: %v", err)
} else {
targets = append(targets, target)
}
}
l.Targets = targets
go l.process()
l.open = true
return nil
} | go | func (l *coreLogger) Open() error {
l.lock.Lock()
defer l.lock.Unlock()
if l.open {
return nil
}
if l.ErrorWriter == nil {
return errors.New("Logger.ErrorWriter must be set.")
}
if l.BufferSize < 0 {
return errors.New("Logger.BufferSize must be no less than 0.")
}
if l.CallStackDepth < 0 {
return errors.New("Logger.CallStackDepth must be no less than 0.")
}
l.entries = make(chan *Entry, l.BufferSize)
var targets []Target
for _, target := range l.Targets {
if err := target.Open(l.ErrorWriter); err != nil {
fmt.Fprintf(l.ErrorWriter, "Failed to open target: %v", err)
} else {
targets = append(targets, target)
}
}
l.Targets = targets
go l.process()
l.open = true
return nil
} | [
"func",
"(",
"l",
"*",
"coreLogger",
")",
"Open",
"(",
")",
"error",
"{",
"l",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"l",
".",
"open",
"{",
"return",
"nil",
"\n",
"}",
"\n\... | // Open prepares the logger and the targets for logging purpose.
// Open must be called before any message can be logged. | [
"Open",
"prepares",
"the",
"logger",
"and",
"the",
"targets",
"for",
"logging",
"purpose",
".",
"Open",
"must",
"be",
"called",
"before",
"any",
"message",
"can",
"be",
"logged",
"."
] | 610cdd147d9aff9523eed107898d2e87ee5336aa | https://github.com/go-ozzo/ozzo-log/blob/610cdd147d9aff9523eed107898d2e87ee5336aa/logger.go#L209-L243 |
17,898 | go-ozzo/ozzo-log | logger.go | process | func (l *coreLogger) process() {
for {
entry := <-l.entries
for _, target := range l.Targets {
target.Process(entry)
}
if entry == nil {
break
}
}
} | go | func (l *coreLogger) process() {
for {
entry := <-l.entries
for _, target := range l.Targets {
target.Process(entry)
}
if entry == nil {
break
}
}
} | [
"func",
"(",
"l",
"*",
"coreLogger",
")",
"process",
"(",
")",
"{",
"for",
"{",
"entry",
":=",
"<-",
"l",
".",
"entries",
"\n",
"for",
"_",
",",
"target",
":=",
"range",
"l",
".",
"Targets",
"{",
"target",
".",
"Process",
"(",
"entry",
")",
"\n",... | // process sends the messages to targets for processing. | [
"process",
"sends",
"the",
"messages",
"to",
"targets",
"for",
"processing",
"."
] | 610cdd147d9aff9523eed107898d2e87ee5336aa | https://github.com/go-ozzo/ozzo-log/blob/610cdd147d9aff9523eed107898d2e87ee5336aa/logger.go#L246-L256 |
17,899 | go-ozzo/ozzo-log | logger.go | Close | func (l *coreLogger) Close() {
if !l.open {
return
}
l.open = false
// use a nil entry to signal the close of logger
l.entries <- nil
for _, target := range l.Targets {
target.Close()
}
} | go | func (l *coreLogger) Close() {
if !l.open {
return
}
l.open = false
// use a nil entry to signal the close of logger
l.entries <- nil
for _, target := range l.Targets {
target.Close()
}
} | [
"func",
"(",
"l",
"*",
"coreLogger",
")",
"Close",
"(",
")",
"{",
"if",
"!",
"l",
".",
"open",
"{",
"return",
"\n",
"}",
"\n",
"l",
".",
"open",
"=",
"false",
"\n",
"// use a nil entry to signal the close of logger",
"l",
".",
"entries",
"<-",
"nil",
"... | // Close closes the logger and the targets.
// Existing messages will be processed before the targets are closed.
// New incoming messages will be discarded after calling this method. | [
"Close",
"closes",
"the",
"logger",
"and",
"the",
"targets",
".",
"Existing",
"messages",
"will",
"be",
"processed",
"before",
"the",
"targets",
"are",
"closed",
".",
"New",
"incoming",
"messages",
"will",
"be",
"discarded",
"after",
"calling",
"this",
"method... | 610cdd147d9aff9523eed107898d2e87ee5336aa | https://github.com/go-ozzo/ozzo-log/blob/610cdd147d9aff9523eed107898d2e87ee5336aa/logger.go#L261-L271 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.