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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
21,200 | beanstalkd/go-beanstalk | tubeset.go | Reserve | func (t *TubeSet) Reserve(timeout time.Duration) (id uint64, body []byte, err error) {
r, err := t.Conn.cmd(nil, t, nil, "reserve-with-timeout", dur(timeout))
if err != nil {
return 0, nil, err
}
body, err = t.Conn.readResp(r, true, "RESERVED %d", &id)
if err != nil {
return 0, nil, err
}
return id, body, ni... | go | func (t *TubeSet) Reserve(timeout time.Duration) (id uint64, body []byte, err error) {
r, err := t.Conn.cmd(nil, t, nil, "reserve-with-timeout", dur(timeout))
if err != nil {
return 0, nil, err
}
body, err = t.Conn.readResp(r, true, "RESERVED %d", &id)
if err != nil {
return 0, nil, err
}
return id, body, ni... | [
"func",
"(",
"t",
"*",
"TubeSet",
")",
"Reserve",
"(",
"timeout",
"time",
".",
"Duration",
")",
"(",
"id",
"uint64",
",",
"body",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"r",
",",
"err",
":=",
"t",
".",
"Conn",
".",
"cmd",
"(",
"nil",
... | // Reserve reserves and returns a job from one of the tubes in t. If no
// job is available before time timeout has passed, Reserve returns a
// ConnError recording ErrTimeout.
//
// Typically, a client will reserve a job, perform some work, then delete
// the job with Conn.Delete. | [
"Reserve",
"reserves",
"and",
"returns",
"a",
"job",
"from",
"one",
"of",
"the",
"tubes",
"in",
"t",
".",
"If",
"no",
"job",
"is",
"available",
"before",
"time",
"timeout",
"has",
"passed",
"Reserve",
"returns",
"a",
"ConnError",
"recording",
"ErrTimeout",
... | 7a112881e6c4f85f0d98f8929536e775d31fb4de | https://github.com/beanstalkd/go-beanstalk/blob/7a112881e6c4f85f0d98f8929536e775d31fb4de/tubeset.go#L29-L39 |
21,201 | beanstalkd/go-beanstalk | tube.go | Put | func (t *Tube) Put(body []byte, pri uint32, delay, ttr time.Duration) (id uint64, err error) {
r, err := t.Conn.cmd(t, nil, body, "put", pri, dur(delay), dur(ttr))
if err != nil {
return 0, err
}
_, err = t.Conn.readResp(r, false, "INSERTED %d", &id)
if err != nil {
return 0, err
}
return id, nil
} | go | func (t *Tube) Put(body []byte, pri uint32, delay, ttr time.Duration) (id uint64, err error) {
r, err := t.Conn.cmd(t, nil, body, "put", pri, dur(delay), dur(ttr))
if err != nil {
return 0, err
}
_, err = t.Conn.readResp(r, false, "INSERTED %d", &id)
if err != nil {
return 0, err
}
return id, nil
} | [
"func",
"(",
"t",
"*",
"Tube",
")",
"Put",
"(",
"body",
"[",
"]",
"byte",
",",
"pri",
"uint32",
",",
"delay",
",",
"ttr",
"time",
".",
"Duration",
")",
"(",
"id",
"uint64",
",",
"err",
"error",
")",
"{",
"r",
",",
"err",
":=",
"t",
".",
"Conn... | // Put puts a job into tube t with priority pri and TTR ttr, and returns
// the id of the newly-created job. If delay is nonzero, the server will
// wait the given amount of time after returning to the client and before
// putting the job into the ready queue. | [
"Put",
"puts",
"a",
"job",
"into",
"tube",
"t",
"with",
"priority",
"pri",
"and",
"TTR",
"ttr",
"and",
"returns",
"the",
"id",
"of",
"the",
"newly",
"-",
"created",
"job",
".",
"If",
"delay",
"is",
"nonzero",
"the",
"server",
"will",
"wait",
"the",
"... | 7a112881e6c4f85f0d98f8929536e775d31fb4de | https://github.com/beanstalkd/go-beanstalk/blob/7a112881e6c4f85f0d98f8929536e775d31fb4de/tube.go#L18-L28 |
21,202 | beanstalkd/go-beanstalk | tube.go | PeekDelayed | func (t *Tube) PeekDelayed() (id uint64, body []byte, err error) {
r, err := t.Conn.cmd(t, nil, nil, "peek-delayed")
if err != nil {
return 0, nil, err
}
body, err = t.Conn.readResp(r, true, "FOUND %d", &id)
if err != nil {
return 0, nil, err
}
return id, body, nil
} | go | func (t *Tube) PeekDelayed() (id uint64, body []byte, err error) {
r, err := t.Conn.cmd(t, nil, nil, "peek-delayed")
if err != nil {
return 0, nil, err
}
body, err = t.Conn.readResp(r, true, "FOUND %d", &id)
if err != nil {
return 0, nil, err
}
return id, body, nil
} | [
"func",
"(",
"t",
"*",
"Tube",
")",
"PeekDelayed",
"(",
")",
"(",
"id",
"uint64",
",",
"body",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"r",
",",
"err",
":=",
"t",
".",
"Conn",
".",
"cmd",
"(",
"t",
",",
"nil",
",",
"nil",
",",
"\""... | // PeekDelayed gets a copy of the delayed job that is next to be
// put in t's ready queue. | [
"PeekDelayed",
"gets",
"a",
"copy",
"of",
"the",
"delayed",
"job",
"that",
"is",
"next",
"to",
"be",
"put",
"in",
"t",
"s",
"ready",
"queue",
"."
] | 7a112881e6c4f85f0d98f8929536e775d31fb4de | https://github.com/beanstalkd/go-beanstalk/blob/7a112881e6c4f85f0d98f8929536e775d31fb4de/tube.go#L45-L55 |
21,203 | beanstalkd/go-beanstalk | tube.go | Kick | func (t *Tube) Kick(bound int) (n int, err error) {
r, err := t.Conn.cmd(t, nil, nil, "kick", bound)
if err != nil {
return 0, err
}
_, err = t.Conn.readResp(r, false, "KICKED %d", &n)
if err != nil {
return 0, err
}
return n, nil
} | go | func (t *Tube) Kick(bound int) (n int, err error) {
r, err := t.Conn.cmd(t, nil, nil, "kick", bound)
if err != nil {
return 0, err
}
_, err = t.Conn.readResp(r, false, "KICKED %d", &n)
if err != nil {
return 0, err
}
return n, nil
} | [
"func",
"(",
"t",
"*",
"Tube",
")",
"Kick",
"(",
"bound",
"int",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"r",
",",
"err",
":=",
"t",
".",
"Conn",
".",
"cmd",
"(",
"t",
",",
"nil",
",",
"nil",
",",
"\"",
"\"",
",",
"bound",
")... | // Kick takes up to bound jobs from the holding area and moves them into
// the ready queue, then returns the number of jobs moved. Jobs will be
// taken in the order in which they were last buried. | [
"Kick",
"takes",
"up",
"to",
"bound",
"jobs",
"from",
"the",
"holding",
"area",
"and",
"moves",
"them",
"into",
"the",
"ready",
"queue",
"then",
"returns",
"the",
"number",
"of",
"jobs",
"moved",
".",
"Jobs",
"will",
"be",
"taken",
"in",
"the",
"order",
... | 7a112881e6c4f85f0d98f8929536e775d31fb4de | https://github.com/beanstalkd/go-beanstalk/blob/7a112881e6c4f85f0d98f8929536e775d31fb4de/tube.go#L74-L84 |
21,204 | beanstalkd/go-beanstalk | tube.go | Stats | func (t *Tube) Stats() (map[string]string, error) {
r, err := t.Conn.cmd(nil, nil, nil, "stats-tube", t.Name)
if err != nil {
return nil, err
}
body, err := t.Conn.readResp(r, true, "OK")
return parseDict(body), err
} | go | func (t *Tube) Stats() (map[string]string, error) {
r, err := t.Conn.cmd(nil, nil, nil, "stats-tube", t.Name)
if err != nil {
return nil, err
}
body, err := t.Conn.readResp(r, true, "OK")
return parseDict(body), err
} | [
"func",
"(",
"t",
"*",
"Tube",
")",
"Stats",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"r",
",",
"err",
":=",
"t",
".",
"Conn",
".",
"cmd",
"(",
"nil",
",",
"nil",
",",
"nil",
",",
"\"",
"\"",
",",
"t",
"... | // Stats retrieves statistics about tube t. | [
"Stats",
"retrieves",
"statistics",
"about",
"tube",
"t",
"."
] | 7a112881e6c4f85f0d98f8929536e775d31fb4de | https://github.com/beanstalkd/go-beanstalk/blob/7a112881e6c4f85f0d98f8929536e775d31fb4de/tube.go#L87-L94 |
21,205 | beanstalkd/go-beanstalk | tube.go | Pause | func (t *Tube) Pause(d time.Duration) error {
r, err := t.Conn.cmd(nil, nil, nil, "pause-tube", t.Name, dur(d))
if err != nil {
return err
}
_, err = t.Conn.readResp(r, false, "PAUSED")
if err != nil {
return err
}
return nil
} | go | func (t *Tube) Pause(d time.Duration) error {
r, err := t.Conn.cmd(nil, nil, nil, "pause-tube", t.Name, dur(d))
if err != nil {
return err
}
_, err = t.Conn.readResp(r, false, "PAUSED")
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"t",
"*",
"Tube",
")",
"Pause",
"(",
"d",
"time",
".",
"Duration",
")",
"error",
"{",
"r",
",",
"err",
":=",
"t",
".",
"Conn",
".",
"cmd",
"(",
"nil",
",",
"nil",
",",
"nil",
",",
"\"",
"\"",
",",
"t",
".",
"Name",
",",
"dur",
... | // Pause pauses new reservations in t for time d. | [
"Pause",
"pauses",
"new",
"reservations",
"in",
"t",
"for",
"time",
"d",
"."
] | 7a112881e6c4f85f0d98f8929536e775d31fb4de | https://github.com/beanstalkd/go-beanstalk/blob/7a112881e6c4f85f0d98f8929536e775d31fb4de/tube.go#L97-L107 |
21,206 | hashicorp/go-immutable-radix | iradix.go | Txn | func (t *Tree) Txn() *Txn {
txn := &Txn{
root: t.root,
snap: t.root,
size: t.size,
}
return txn
} | go | func (t *Tree) Txn() *Txn {
txn := &Txn{
root: t.root,
snap: t.root,
size: t.size,
}
return txn
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Txn",
"(",
")",
"*",
"Txn",
"{",
"txn",
":=",
"&",
"Txn",
"{",
"root",
":",
"t",
".",
"root",
",",
"snap",
":",
"t",
".",
"root",
",",
"size",
":",
"t",
".",
"size",
",",
"}",
"\n",
"return",
"txn",
"\... | // Txn starts a new transaction that can be used to mutate the tree | [
"Txn",
"starts",
"a",
"new",
"transaction",
"that",
"can",
"be",
"used",
"to",
"mutate",
"the",
"tree"
] | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/iradix.go#L80-L87 |
21,207 | hashicorp/go-immutable-radix | iradix.go | trackChannel | func (t *Txn) trackChannel(ch chan struct{}) {
// In overflow, make sure we don't store any more objects.
if t.trackOverflow {
return
}
// If this would overflow the state we reject it and set the flag (since
// we aren't tracking everything that's required any longer).
if len(t.trackChannels) >= defaultModifi... | go | func (t *Txn) trackChannel(ch chan struct{}) {
// In overflow, make sure we don't store any more objects.
if t.trackOverflow {
return
}
// If this would overflow the state we reject it and set the flag (since
// we aren't tracking everything that's required any longer).
if len(t.trackChannels) >= defaultModifi... | [
"func",
"(",
"t",
"*",
"Txn",
")",
"trackChannel",
"(",
"ch",
"chan",
"struct",
"{",
"}",
")",
"{",
"// In overflow, make sure we don't store any more objects.",
"if",
"t",
".",
"trackOverflow",
"{",
"return",
"\n",
"}",
"\n\n",
"// If this would overflow the state ... | // trackChannel safely attempts to track the given mutation channel, setting the
// overflow flag if we can no longer track any more. This limits the amount of
// state that will accumulate during a transaction and we have a slower algorithm
// to switch to if we overflow. | [
"trackChannel",
"safely",
"attempts",
"to",
"track",
"the",
"given",
"mutation",
"channel",
"setting",
"the",
"overflow",
"flag",
"if",
"we",
"can",
"no",
"longer",
"track",
"any",
"more",
".",
"This",
"limits",
"the",
"amount",
"of",
"state",
"that",
"will"... | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/iradix.go#L100-L126 |
21,208 | hashicorp/go-immutable-radix | iradix.go | writeNode | func (t *Txn) writeNode(n *Node, forLeafUpdate bool) *Node {
// Ensure the writable set exists.
if t.writable == nil {
lru, err := simplelru.NewLRU(defaultModifiedCache, nil)
if err != nil {
panic(err)
}
t.writable = lru
}
// If this node has already been modified, we can continue to use it
// during t... | go | func (t *Txn) writeNode(n *Node, forLeafUpdate bool) *Node {
// Ensure the writable set exists.
if t.writable == nil {
lru, err := simplelru.NewLRU(defaultModifiedCache, nil)
if err != nil {
panic(err)
}
t.writable = lru
}
// If this node has already been modified, we can continue to use it
// during t... | [
"func",
"(",
"t",
"*",
"Txn",
")",
"writeNode",
"(",
"n",
"*",
"Node",
",",
"forLeafUpdate",
"bool",
")",
"*",
"Node",
"{",
"// Ensure the writable set exists.",
"if",
"t",
".",
"writable",
"==",
"nil",
"{",
"lru",
",",
"err",
":=",
"simplelru",
".",
"... | // writeNode returns a node to be modified, if the current node has already been
// modified during the course of the transaction, it is used in-place. Set
// forLeafUpdate to true if you are getting a write node to update the leaf,
// which will set leaf mutation tracking appropriately as well. | [
"writeNode",
"returns",
"a",
"node",
"to",
"be",
"modified",
"if",
"the",
"current",
"node",
"has",
"already",
"been",
"modified",
"during",
"the",
"course",
"of",
"the",
"transaction",
"it",
"is",
"used",
"in",
"-",
"place",
".",
"Set",
"forLeafUpdate",
"... | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/iradix.go#L132-L184 |
21,209 | hashicorp/go-immutable-radix | iradix.go | trackChannelsAndCount | func (t *Txn) trackChannelsAndCount(n *Node) int {
// Count only leaf nodes
leaves := 0
if n.leaf != nil {
leaves = 1
}
// Mark this node as being mutated.
if t.trackMutate {
t.trackChannel(n.mutateCh)
}
// Mark its leaf as being mutated, if appropriate.
if t.trackMutate && n.leaf != nil {
t.trackChanne... | go | func (t *Txn) trackChannelsAndCount(n *Node) int {
// Count only leaf nodes
leaves := 0
if n.leaf != nil {
leaves = 1
}
// Mark this node as being mutated.
if t.trackMutate {
t.trackChannel(n.mutateCh)
}
// Mark its leaf as being mutated, if appropriate.
if t.trackMutate && n.leaf != nil {
t.trackChanne... | [
"func",
"(",
"t",
"*",
"Txn",
")",
"trackChannelsAndCount",
"(",
"n",
"*",
"Node",
")",
"int",
"{",
"// Count only leaf nodes",
"leaves",
":=",
"0",
"\n",
"if",
"n",
".",
"leaf",
"!=",
"nil",
"{",
"leaves",
"=",
"1",
"\n",
"}",
"\n",
"// Mark this node... | // Visit all the nodes in the tree under n, and add their mutateChannels to the transaction
// Returns the size of the subtree visited | [
"Visit",
"all",
"the",
"nodes",
"in",
"the",
"tree",
"under",
"n",
"and",
"add",
"their",
"mutateChannels",
"to",
"the",
"transaction",
"Returns",
"the",
"size",
"of",
"the",
"subtree",
"visited"
] | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/iradix.go#L188-L209 |
21,210 | hashicorp/go-immutable-radix | iradix.go | mergeChild | func (t *Txn) mergeChild(n *Node) {
// Mark the child node as being mutated since we are about to abandon
// it. We don't need to mark the leaf since we are retaining it if it
// is there.
e := n.edges[0]
child := e.node
if t.trackMutate {
t.trackChannel(child.mutateCh)
}
// Merge the nodes.
n.prefix = conc... | go | func (t *Txn) mergeChild(n *Node) {
// Mark the child node as being mutated since we are about to abandon
// it. We don't need to mark the leaf since we are retaining it if it
// is there.
e := n.edges[0]
child := e.node
if t.trackMutate {
t.trackChannel(child.mutateCh)
}
// Merge the nodes.
n.prefix = conc... | [
"func",
"(",
"t",
"*",
"Txn",
")",
"mergeChild",
"(",
"n",
"*",
"Node",
")",
"{",
"// Mark the child node as being mutated since we are about to abandon",
"// it. We don't need to mark the leaf since we are retaining it if it",
"// is there.",
"e",
":=",
"n",
".",
"edges",
... | // mergeChild is called to collapse the given node with its child. This is only
// called when the given node is not a leaf and has a single edge. | [
"mergeChild",
"is",
"called",
"to",
"collapse",
"the",
"given",
"node",
"with",
"its",
"child",
".",
"This",
"is",
"only",
"called",
"when",
"the",
"given",
"node",
"is",
"not",
"a",
"leaf",
"and",
"has",
"a",
"single",
"edge",
"."
] | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/iradix.go#L213-L232 |
21,211 | hashicorp/go-immutable-radix | iradix.go | delete | func (t *Txn) delete(parent, n *Node, search []byte) (*Node, *leafNode) {
// Check for key exhaustion
if len(search) == 0 {
if !n.isLeaf() {
return nil, nil
}
// Copy the pointer in case we are in a transaction that already
// modified this node since the node will be reused. Any changes
// made to the n... | go | func (t *Txn) delete(parent, n *Node, search []byte) (*Node, *leafNode) {
// Check for key exhaustion
if len(search) == 0 {
if !n.isLeaf() {
return nil, nil
}
// Copy the pointer in case we are in a transaction that already
// modified this node since the node will be reused. Any changes
// made to the n... | [
"func",
"(",
"t",
"*",
"Txn",
")",
"delete",
"(",
"parent",
",",
"n",
"*",
"Node",
",",
"search",
"[",
"]",
"byte",
")",
"(",
"*",
"Node",
",",
"*",
"leafNode",
")",
"{",
"// Check for key exhaustion",
"if",
"len",
"(",
"search",
")",
"==",
"0",
... | // delete does a recursive deletion | [
"delete",
"does",
"a",
"recursive",
"deletion"
] | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/iradix.go#L335-L388 |
21,212 | hashicorp/go-immutable-radix | iradix.go | Insert | func (t *Txn) Insert(k []byte, v interface{}) (interface{}, bool) {
newRoot, oldVal, didUpdate := t.insert(t.root, k, k, v)
if newRoot != nil {
t.root = newRoot
}
if !didUpdate {
t.size++
}
return oldVal, didUpdate
} | go | func (t *Txn) Insert(k []byte, v interface{}) (interface{}, bool) {
newRoot, oldVal, didUpdate := t.insert(t.root, k, k, v)
if newRoot != nil {
t.root = newRoot
}
if !didUpdate {
t.size++
}
return oldVal, didUpdate
} | [
"func",
"(",
"t",
"*",
"Txn",
")",
"Insert",
"(",
"k",
"[",
"]",
"byte",
",",
"v",
"interface",
"{",
"}",
")",
"(",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"newRoot",
",",
"oldVal",
",",
"didUpdate",
":=",
"t",
".",
"insert",
"(",
"t",
... | // Insert is used to add or update a given key. The return provides
// the previous value and a bool indicating if any was set. | [
"Insert",
"is",
"used",
"to",
"add",
"or",
"update",
"a",
"given",
"key",
".",
"The",
"return",
"provides",
"the",
"previous",
"value",
"and",
"a",
"bool",
"indicating",
"if",
"any",
"was",
"set",
"."
] | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/iradix.go#L442-L451 |
21,213 | hashicorp/go-immutable-radix | iradix.go | Delete | func (t *Txn) Delete(k []byte) (interface{}, bool) {
newRoot, leaf := t.delete(nil, t.root, k)
if newRoot != nil {
t.root = newRoot
}
if leaf != nil {
t.size--
return leaf.val, true
}
return nil, false
} | go | func (t *Txn) Delete(k []byte) (interface{}, bool) {
newRoot, leaf := t.delete(nil, t.root, k)
if newRoot != nil {
t.root = newRoot
}
if leaf != nil {
t.size--
return leaf.val, true
}
return nil, false
} | [
"func",
"(",
"t",
"*",
"Txn",
")",
"Delete",
"(",
"k",
"[",
"]",
"byte",
")",
"(",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"newRoot",
",",
"leaf",
":=",
"t",
".",
"delete",
"(",
"nil",
",",
"t",
".",
"root",
",",
"k",
")",
"\n",
"if",... | // Delete is used to delete a given key. Returns the old value if any,
// and a bool indicating if the key was set. | [
"Delete",
"is",
"used",
"to",
"delete",
"a",
"given",
"key",
".",
"Returns",
"the",
"old",
"value",
"if",
"any",
"and",
"a",
"bool",
"indicating",
"if",
"the",
"key",
"was",
"set",
"."
] | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/iradix.go#L455-L465 |
21,214 | hashicorp/go-immutable-radix | iradix.go | DeletePrefix | func (t *Txn) DeletePrefix(prefix []byte) bool {
newRoot, numDeletions := t.deletePrefix(nil, t.root, prefix)
if newRoot != nil {
t.root = newRoot
t.size = t.size - numDeletions
return true
}
return false
} | go | func (t *Txn) DeletePrefix(prefix []byte) bool {
newRoot, numDeletions := t.deletePrefix(nil, t.root, prefix)
if newRoot != nil {
t.root = newRoot
t.size = t.size - numDeletions
return true
}
return false
} | [
"func",
"(",
"t",
"*",
"Txn",
")",
"DeletePrefix",
"(",
"prefix",
"[",
"]",
"byte",
")",
"bool",
"{",
"newRoot",
",",
"numDeletions",
":=",
"t",
".",
"deletePrefix",
"(",
"nil",
",",
"t",
".",
"root",
",",
"prefix",
")",
"\n",
"if",
"newRoot",
"!="... | // DeletePrefix is used to delete an entire subtree that matches the prefix
// This will delete all nodes under that prefix | [
"DeletePrefix",
"is",
"used",
"to",
"delete",
"an",
"entire",
"subtree",
"that",
"matches",
"the",
"prefix",
"This",
"will",
"delete",
"all",
"nodes",
"under",
"that",
"prefix"
] | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/iradix.go#L469-L478 |
21,215 | hashicorp/go-immutable-radix | iradix.go | GetWatch | func (t *Txn) GetWatch(k []byte) (<-chan struct{}, interface{}, bool) {
return t.root.GetWatch(k)
} | go | func (t *Txn) GetWatch(k []byte) (<-chan struct{}, interface{}, bool) {
return t.root.GetWatch(k)
} | [
"func",
"(",
"t",
"*",
"Txn",
")",
"GetWatch",
"(",
"k",
"[",
"]",
"byte",
")",
"(",
"<-",
"chan",
"struct",
"{",
"}",
",",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"return",
"t",
".",
"root",
".",
"GetWatch",
"(",
"k",
")",
"\n",
"}"
] | // GetWatch is used to lookup a specific key, returning
// the watch channel, value and if it was found | [
"GetWatch",
"is",
"used",
"to",
"lookup",
"a",
"specific",
"key",
"returning",
"the",
"watch",
"channel",
"value",
"and",
"if",
"it",
"was",
"found"
] | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/iradix.go#L495-L497 |
21,216 | hashicorp/go-immutable-radix | iradix.go | Commit | func (t *Txn) Commit() *Tree {
nt := t.CommitOnly()
if t.trackMutate {
t.Notify()
}
return nt
} | go | func (t *Txn) Commit() *Tree {
nt := t.CommitOnly()
if t.trackMutate {
t.Notify()
}
return nt
} | [
"func",
"(",
"t",
"*",
"Txn",
")",
"Commit",
"(",
")",
"*",
"Tree",
"{",
"nt",
":=",
"t",
".",
"CommitOnly",
"(",
")",
"\n",
"if",
"t",
".",
"trackMutate",
"{",
"t",
".",
"Notify",
"(",
")",
"\n",
"}",
"\n",
"return",
"nt",
"\n",
"}"
] | // Commit is used to finalize the transaction and return a new tree. If mutation
// tracking is turned on then notifications will also be issued. | [
"Commit",
"is",
"used",
"to",
"finalize",
"the",
"transaction",
"and",
"return",
"a",
"new",
"tree",
".",
"If",
"mutation",
"tracking",
"is",
"turned",
"on",
"then",
"notifications",
"will",
"also",
"be",
"issued",
"."
] | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/iradix.go#L501-L507 |
21,217 | hashicorp/go-immutable-radix | iradix.go | CommitOnly | func (t *Txn) CommitOnly() *Tree {
nt := &Tree{t.root, t.size}
t.writable = nil
return nt
} | go | func (t *Txn) CommitOnly() *Tree {
nt := &Tree{t.root, t.size}
t.writable = nil
return nt
} | [
"func",
"(",
"t",
"*",
"Txn",
")",
"CommitOnly",
"(",
")",
"*",
"Tree",
"{",
"nt",
":=",
"&",
"Tree",
"{",
"t",
".",
"root",
",",
"t",
".",
"size",
"}",
"\n",
"t",
".",
"writable",
"=",
"nil",
"\n",
"return",
"nt",
"\n",
"}"
] | // CommitOnly is used to finalize the transaction and return a new tree, but
// does not issue any notifications until Notify is called. | [
"CommitOnly",
"is",
"used",
"to",
"finalize",
"the",
"transaction",
"and",
"return",
"a",
"new",
"tree",
"but",
"does",
"not",
"issue",
"any",
"notifications",
"until",
"Notify",
"is",
"called",
"."
] | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/iradix.go#L511-L515 |
21,218 | hashicorp/go-immutable-radix | iradix.go | slowNotify | func (t *Txn) slowNotify() {
snapIter := t.snap.rawIterator()
rootIter := t.root.rawIterator()
for snapIter.Front() != nil || rootIter.Front() != nil {
// If we've exhausted the nodes in the old snapshot, we know
// there's nothing remaining to notify.
if snapIter.Front() == nil {
return
}
snapElem := s... | go | func (t *Txn) slowNotify() {
snapIter := t.snap.rawIterator()
rootIter := t.root.rawIterator()
for snapIter.Front() != nil || rootIter.Front() != nil {
// If we've exhausted the nodes in the old snapshot, we know
// there's nothing remaining to notify.
if snapIter.Front() == nil {
return
}
snapElem := s... | [
"func",
"(",
"t",
"*",
"Txn",
")",
"slowNotify",
"(",
")",
"{",
"snapIter",
":=",
"t",
".",
"snap",
".",
"rawIterator",
"(",
")",
"\n",
"rootIter",
":=",
"t",
".",
"root",
".",
"rawIterator",
"(",
")",
"\n",
"for",
"snapIter",
".",
"Front",
"(",
... | // slowNotify does a complete comparison of the before and after trees in order
// to trigger notifications. This doesn't require any additional state but it
// is very expensive to compute. | [
"slowNotify",
"does",
"a",
"complete",
"comparison",
"of",
"the",
"before",
"and",
"after",
"trees",
"in",
"order",
"to",
"trigger",
"notifications",
".",
"This",
"doesn",
"t",
"require",
"any",
"additional",
"state",
"but",
"it",
"is",
"very",
"expensive",
... | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/iradix.go#L520-L578 |
21,219 | hashicorp/go-immutable-radix | iradix.go | Notify | func (t *Txn) Notify() {
if !t.trackMutate {
return
}
// If we've overflowed the tracking state we can't use it in any way and
// need to do a full tree compare.
if t.trackOverflow {
t.slowNotify()
} else {
for ch := range t.trackChannels {
close(ch)
}
}
// Clean up the tracking state so that a re-... | go | func (t *Txn) Notify() {
if !t.trackMutate {
return
}
// If we've overflowed the tracking state we can't use it in any way and
// need to do a full tree compare.
if t.trackOverflow {
t.slowNotify()
} else {
for ch := range t.trackChannels {
close(ch)
}
}
// Clean up the tracking state so that a re-... | [
"func",
"(",
"t",
"*",
"Txn",
")",
"Notify",
"(",
")",
"{",
"if",
"!",
"t",
".",
"trackMutate",
"{",
"return",
"\n",
"}",
"\n\n",
"// If we've overflowed the tracking state we can't use it in any way and",
"// need to do a full tree compare.",
"if",
"t",
".",
"track... | // Notify is used along with TrackMutate to trigger notifications. This must
// only be done once a transaction is committed via CommitOnly, and it is called
// automatically by Commit. | [
"Notify",
"is",
"used",
"along",
"with",
"TrackMutate",
"to",
"trigger",
"notifications",
".",
"This",
"must",
"only",
"be",
"done",
"once",
"a",
"transaction",
"is",
"committed",
"via",
"CommitOnly",
"and",
"it",
"is",
"called",
"automatically",
"by",
"Commit... | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/iradix.go#L583-L602 |
21,220 | hashicorp/go-immutable-radix | iradix.go | Insert | func (t *Tree) Insert(k []byte, v interface{}) (*Tree, interface{}, bool) {
txn := t.Txn()
old, ok := txn.Insert(k, v)
return txn.Commit(), old, ok
} | go | func (t *Tree) Insert(k []byte, v interface{}) (*Tree, interface{}, bool) {
txn := t.Txn()
old, ok := txn.Insert(k, v)
return txn.Commit(), old, ok
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Insert",
"(",
"k",
"[",
"]",
"byte",
",",
"v",
"interface",
"{",
"}",
")",
"(",
"*",
"Tree",
",",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"txn",
":=",
"t",
".",
"Txn",
"(",
")",
"\n",
"old",
",",
... | // Insert is used to add or update a given key. The return provides
// the new tree, previous value and a bool indicating if any was set. | [
"Insert",
"is",
"used",
"to",
"add",
"or",
"update",
"a",
"given",
"key",
".",
"The",
"return",
"provides",
"the",
"new",
"tree",
"previous",
"value",
"and",
"a",
"bool",
"indicating",
"if",
"any",
"was",
"set",
"."
] | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/iradix.go#L606-L610 |
21,221 | hashicorp/go-immutable-radix | iradix.go | Delete | func (t *Tree) Delete(k []byte) (*Tree, interface{}, bool) {
txn := t.Txn()
old, ok := txn.Delete(k)
return txn.Commit(), old, ok
} | go | func (t *Tree) Delete(k []byte) (*Tree, interface{}, bool) {
txn := t.Txn()
old, ok := txn.Delete(k)
return txn.Commit(), old, ok
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Delete",
"(",
"k",
"[",
"]",
"byte",
")",
"(",
"*",
"Tree",
",",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"txn",
":=",
"t",
".",
"Txn",
"(",
")",
"\n",
"old",
",",
"ok",
":=",
"txn",
".",
"Delete",
... | // Delete is used to delete a given key. Returns the new tree,
// old value if any, and a bool indicating if the key was set. | [
"Delete",
"is",
"used",
"to",
"delete",
"a",
"given",
"key",
".",
"Returns",
"the",
"new",
"tree",
"old",
"value",
"if",
"any",
"and",
"a",
"bool",
"indicating",
"if",
"the",
"key",
"was",
"set",
"."
] | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/iradix.go#L614-L618 |
21,222 | hashicorp/go-immutable-radix | iradix.go | DeletePrefix | func (t *Tree) DeletePrefix(k []byte) (*Tree, bool) {
txn := t.Txn()
ok := txn.DeletePrefix(k)
return txn.Commit(), ok
} | go | func (t *Tree) DeletePrefix(k []byte) (*Tree, bool) {
txn := t.Txn()
ok := txn.DeletePrefix(k)
return txn.Commit(), ok
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"DeletePrefix",
"(",
"k",
"[",
"]",
"byte",
")",
"(",
"*",
"Tree",
",",
"bool",
")",
"{",
"txn",
":=",
"t",
".",
"Txn",
"(",
")",
"\n",
"ok",
":=",
"txn",
".",
"DeletePrefix",
"(",
"k",
")",
"\n",
"return",... | // DeletePrefix is used to delete all nodes starting with a given prefix. Returns the new tree,
// and a bool indicating if the prefix matched any nodes | [
"DeletePrefix",
"is",
"used",
"to",
"delete",
"all",
"nodes",
"starting",
"with",
"a",
"given",
"prefix",
".",
"Returns",
"the",
"new",
"tree",
"and",
"a",
"bool",
"indicating",
"if",
"the",
"prefix",
"matched",
"any",
"nodes"
] | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/iradix.go#L622-L626 |
21,223 | hashicorp/go-immutable-radix | iradix.go | longestPrefix | func longestPrefix(k1, k2 []byte) int {
max := len(k1)
if l := len(k2); l < max {
max = l
}
var i int
for i = 0; i < max; i++ {
if k1[i] != k2[i] {
break
}
}
return i
} | go | func longestPrefix(k1, k2 []byte) int {
max := len(k1)
if l := len(k2); l < max {
max = l
}
var i int
for i = 0; i < max; i++ {
if k1[i] != k2[i] {
break
}
}
return i
} | [
"func",
"longestPrefix",
"(",
"k1",
",",
"k2",
"[",
"]",
"byte",
")",
"int",
"{",
"max",
":=",
"len",
"(",
"k1",
")",
"\n",
"if",
"l",
":=",
"len",
"(",
"k2",
")",
";",
"l",
"<",
"max",
"{",
"max",
"=",
"l",
"\n",
"}",
"\n",
"var",
"i",
"... | // longestPrefix finds the length of the shared prefix
// of two strings | [
"longestPrefix",
"finds",
"the",
"length",
"of",
"the",
"shared",
"prefix",
"of",
"two",
"strings"
] | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/iradix.go#L642-L654 |
21,224 | hashicorp/go-immutable-radix | iradix.go | concat | func concat(a, b []byte) []byte {
c := make([]byte, len(a)+len(b))
copy(c, a)
copy(c[len(a):], b)
return c
} | go | func concat(a, b []byte) []byte {
c := make([]byte, len(a)+len(b))
copy(c, a)
copy(c[len(a):], b)
return c
} | [
"func",
"concat",
"(",
"a",
",",
"b",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"c",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"a",
")",
"+",
"len",
"(",
"b",
")",
")",
"\n",
"copy",
"(",
"c",
",",
"a",
")",
"\n",
"copy"... | // concat two byte slices, returning a third new copy | [
"concat",
"two",
"byte",
"slices",
"returning",
"a",
"third",
"new",
"copy"
] | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/iradix.go#L657-L662 |
21,225 | hashicorp/go-immutable-radix | node.go | LongestPrefix | func (n *Node) LongestPrefix(k []byte) ([]byte, interface{}, bool) {
var last *leafNode
search := k
for {
// Look for a leaf node
if n.isLeaf() {
last = n.leaf
}
// Check for key exhaution
if len(search) == 0 {
break
}
// Look for an edge
_, n = n.getEdge(search[0])
if n == nil {
break
... | go | func (n *Node) LongestPrefix(k []byte) ([]byte, interface{}, bool) {
var last *leafNode
search := k
for {
// Look for a leaf node
if n.isLeaf() {
last = n.leaf
}
// Check for key exhaution
if len(search) == 0 {
break
}
// Look for an edge
_, n = n.getEdge(search[0])
if n == nil {
break
... | [
"func",
"(",
"n",
"*",
"Node",
")",
"LongestPrefix",
"(",
"k",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"var",
"last",
"*",
"leafNode",
"\n",
"search",
":=",
"k",
"\n",
"for",
"{",
"// Loo... | // LongestPrefix is like Get, but instead of an
// exact match, it will return the longest prefix match. | [
"LongestPrefix",
"is",
"like",
"Get",
"but",
"instead",
"of",
"an",
"exact",
"match",
"it",
"will",
"return",
"the",
"longest",
"prefix",
"match",
"."
] | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/node.go#L132-L163 |
21,226 | hashicorp/go-immutable-radix | node.go | Minimum | func (n *Node) Minimum() ([]byte, interface{}, bool) {
for {
if n.isLeaf() {
return n.leaf.key, n.leaf.val, true
}
if len(n.edges) > 0 {
n = n.edges[0].node
} else {
break
}
}
return nil, nil, false
} | go | func (n *Node) Minimum() ([]byte, interface{}, bool) {
for {
if n.isLeaf() {
return n.leaf.key, n.leaf.val, true
}
if len(n.edges) > 0 {
n = n.edges[0].node
} else {
break
}
}
return nil, nil, false
} | [
"func",
"(",
"n",
"*",
"Node",
")",
"Minimum",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"for",
"{",
"if",
"n",
".",
"isLeaf",
"(",
")",
"{",
"return",
"n",
".",
"leaf",
".",
"key",
",",
"n",
".",
... | // Minimum is used to return the minimum value in the tree | [
"Minimum",
"is",
"used",
"to",
"return",
"the",
"minimum",
"value",
"in",
"the",
"tree"
] | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/node.go#L166-L178 |
21,227 | hashicorp/go-immutable-radix | node.go | rawIterator | func (n *Node) rawIterator() *rawIterator {
iter := &rawIterator{node: n}
iter.Next()
return iter
} | go | func (n *Node) rawIterator() *rawIterator {
iter := &rawIterator{node: n}
iter.Next()
return iter
} | [
"func",
"(",
"n",
"*",
"Node",
")",
"rawIterator",
"(",
")",
"*",
"rawIterator",
"{",
"iter",
":=",
"&",
"rawIterator",
"{",
"node",
":",
"n",
"}",
"\n",
"iter",
".",
"Next",
"(",
")",
"\n",
"return",
"iter",
"\n",
"}"
] | // rawIterator is used to return a raw iterator at the given node to walk the
// tree. | [
"rawIterator",
"is",
"used",
"to",
"return",
"a",
"raw",
"iterator",
"at",
"the",
"given",
"node",
"to",
"walk",
"the",
"tree",
"."
] | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/node.go#L204-L208 |
21,228 | hashicorp/go-immutable-radix | node.go | WalkPrefix | func (n *Node) WalkPrefix(prefix []byte, fn WalkFn) {
search := prefix
for {
// Check for key exhaution
if len(search) == 0 {
recursiveWalk(n, fn)
return
}
// Look for an edge
_, n = n.getEdge(search[0])
if n == nil {
break
}
// Consume the search prefix
if bytes.HasPrefix(search, n.prefi... | go | func (n *Node) WalkPrefix(prefix []byte, fn WalkFn) {
search := prefix
for {
// Check for key exhaution
if len(search) == 0 {
recursiveWalk(n, fn)
return
}
// Look for an edge
_, n = n.getEdge(search[0])
if n == nil {
break
}
// Consume the search prefix
if bytes.HasPrefix(search, n.prefi... | [
"func",
"(",
"n",
"*",
"Node",
")",
"WalkPrefix",
"(",
"prefix",
"[",
"]",
"byte",
",",
"fn",
"WalkFn",
")",
"{",
"search",
":=",
"prefix",
"\n",
"for",
"{",
"// Check for key exhaution",
"if",
"len",
"(",
"search",
")",
"==",
"0",
"{",
"recursiveWalk"... | // WalkPrefix is used to walk the tree under a prefix | [
"WalkPrefix",
"is",
"used",
"to",
"walk",
"the",
"tree",
"under",
"a",
"prefix"
] | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/node.go#L216-L243 |
21,229 | hashicorp/go-immutable-radix | iter.go | SeekPrefixWatch | func (i *Iterator) SeekPrefixWatch(prefix []byte) (watch <-chan struct{}) {
// Wipe the stack
i.stack = nil
n := i.node
watch = n.mutateCh
search := prefix
for {
// Check for key exhaution
if len(search) == 0 {
i.node = n
return
}
// Look for an edge
_, n = n.getEdge(search[0])
if n == nil {
... | go | func (i *Iterator) SeekPrefixWatch(prefix []byte) (watch <-chan struct{}) {
// Wipe the stack
i.stack = nil
n := i.node
watch = n.mutateCh
search := prefix
for {
// Check for key exhaution
if len(search) == 0 {
i.node = n
return
}
// Look for an edge
_, n = n.getEdge(search[0])
if n == nil {
... | [
"func",
"(",
"i",
"*",
"Iterator",
")",
"SeekPrefixWatch",
"(",
"prefix",
"[",
"]",
"byte",
")",
"(",
"watch",
"<-",
"chan",
"struct",
"{",
"}",
")",
"{",
"// Wipe the stack",
"i",
".",
"stack",
"=",
"nil",
"\n",
"n",
":=",
"i",
".",
"node",
"\n",
... | // SeekPrefixWatch is used to seek the iterator to a given prefix
// and returns the watch channel of the finest granularity | [
"SeekPrefixWatch",
"is",
"used",
"to",
"seek",
"the",
"iterator",
"to",
"a",
"given",
"prefix",
"and",
"returns",
"the",
"watch",
"channel",
"of",
"the",
"finest",
"granularity"
] | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/iter.go#L14-L49 |
21,230 | hashicorp/go-immutable-radix | iter.go | Next | func (i *Iterator) Next() ([]byte, interface{}, bool) {
// Initialize our stack if needed
if i.stack == nil && i.node != nil {
i.stack = []edges{
edges{
edge{node: i.node},
},
}
}
for len(i.stack) > 0 {
// Inspect the last element of the stack
n := len(i.stack)
last := i.stack[n-1]
elem := la... | go | func (i *Iterator) Next() ([]byte, interface{}, bool) {
// Initialize our stack if needed
if i.stack == nil && i.node != nil {
i.stack = []edges{
edges{
edge{node: i.node},
},
}
}
for len(i.stack) > 0 {
// Inspect the last element of the stack
n := len(i.stack)
last := i.stack[n-1]
elem := la... | [
"func",
"(",
"i",
"*",
"Iterator",
")",
"Next",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"// Initialize our stack if needed",
"if",
"i",
".",
"stack",
"==",
"nil",
"&&",
"i",
".",
"node",
"!=",
"nil",
"{",... | // Next returns the next node in order | [
"Next",
"returns",
"the",
"next",
"node",
"in",
"order"
] | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/iter.go#L57-L91 |
21,231 | hashicorp/go-immutable-radix | raw_iter.go | Next | func (i *rawIterator) Next() {
// Initialize our stack if needed.
if i.stack == nil && i.node != nil {
i.stack = []rawStackEntry{
rawStackEntry{
edges: edges{
edge{node: i.node},
},
},
}
}
for len(i.stack) > 0 {
// Inspect the last element of the stack.
n := len(i.stack)
last := i.stac... | go | func (i *rawIterator) Next() {
// Initialize our stack if needed.
if i.stack == nil && i.node != nil {
i.stack = []rawStackEntry{
rawStackEntry{
edges: edges{
edge{node: i.node},
},
},
}
}
for len(i.stack) > 0 {
// Inspect the last element of the stack.
n := len(i.stack)
last := i.stac... | [
"func",
"(",
"i",
"*",
"rawIterator",
")",
"Next",
"(",
")",
"{",
"// Initialize our stack if needed.",
"if",
"i",
".",
"stack",
"==",
"nil",
"&&",
"i",
".",
"node",
"!=",
"nil",
"{",
"i",
".",
"stack",
"=",
"[",
"]",
"rawStackEntry",
"{",
"rawStackEnt... | // Next advances the iterator to the next node. | [
"Next",
"advances",
"the",
"iterator",
"to",
"the",
"next",
"node",
"."
] | 27df80928bb34bb1b0d6d0e01b9e679902e7a6b5 | https://github.com/hashicorp/go-immutable-radix/blob/27df80928bb34bb1b0d6d0e01b9e679902e7a6b5/raw_iter.go#L40-L78 |
21,232 | lestrrat-go/jwx | jwe/serializer.go | Serialize | func (s CompactSerialize) Serialize(m *Message) ([]byte, error) {
if len(m.Recipients) != 1 {
return nil, errors.New("wrong number of recipients for compact serialization")
}
recipient := m.Recipients[0]
// The protected header must be a merge between the message-wide
// protected header AND the recipient head... | go | func (s CompactSerialize) Serialize(m *Message) ([]byte, error) {
if len(m.Recipients) != 1 {
return nil, errors.New("wrong number of recipients for compact serialization")
}
recipient := m.Recipients[0]
// The protected header must be a merge between the message-wide
// protected header AND the recipient head... | [
"func",
"(",
"s",
"CompactSerialize",
")",
"Serialize",
"(",
"m",
"*",
"Message",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"len",
"(",
"m",
".",
"Recipients",
")",
"!=",
"1",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
... | // Serialize converts the message into a JWE compact serialize format byte buffer | [
"Serialize",
"converts",
"the",
"message",
"into",
"a",
"JWE",
"compact",
"serialize",
"format",
"byte",
"buffer"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/serializer.go#L10-L65 |
21,233 | lestrrat-go/jwx | jwe/serializer.go | Serialize | func (s JSONSerialize) Serialize(m *Message) ([]byte, error) {
if s.Pretty {
return json.MarshalIndent(m, "", " ")
}
return json.Marshal(m)
} | go | func (s JSONSerialize) Serialize(m *Message) ([]byte, error) {
if s.Pretty {
return json.MarshalIndent(m, "", " ")
}
return json.Marshal(m)
} | [
"func",
"(",
"s",
"JSONSerialize",
")",
"Serialize",
"(",
"m",
"*",
"Message",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"s",
".",
"Pretty",
"{",
"return",
"json",
".",
"MarshalIndent",
"(",
"m",
",",
"\"",
"\"",
",",
"\"",
"\"",
... | // Serialize converts the message into a JWE JSON serialize format byte buffer | [
"Serialize",
"converts",
"the",
"message",
"into",
"a",
"JWE",
"JSON",
"serialize",
"format",
"byte",
"buffer"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/serializer.go#L68-L73 |
21,234 | lestrrat-go/jwx | jwe/aescbc/aescbc.go | Seal | func (c AesCbcHmac) Seal(dst, nonce, plaintext, data []byte) []byte {
ctlen := len(plaintext)
ciphertext := make([]byte, ctlen+c.Overhead())[:ctlen]
copy(ciphertext, plaintext)
ciphertext = padbuf.PadBuffer(ciphertext).Pad(c.blockCipher.BlockSize())
cbc := cipher.NewCBCEncrypter(c.blockCipher, nonce)
cbc.CryptBl... | go | func (c AesCbcHmac) Seal(dst, nonce, plaintext, data []byte) []byte {
ctlen := len(plaintext)
ciphertext := make([]byte, ctlen+c.Overhead())[:ctlen]
copy(ciphertext, plaintext)
ciphertext = padbuf.PadBuffer(ciphertext).Pad(c.blockCipher.BlockSize())
cbc := cipher.NewCBCEncrypter(c.blockCipher, nonce)
cbc.CryptBl... | [
"func",
"(",
"c",
"AesCbcHmac",
")",
"Seal",
"(",
"dst",
",",
"nonce",
",",
"plaintext",
",",
"data",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"ctlen",
":=",
"len",
"(",
"plaintext",
")",
"\n",
"ciphertext",
":=",
"make",
"(",
"[",
"]",
"byt... | // Seal fulfills the crypto.AEAD interface | [
"Seal",
"fulfills",
"the",
"crypto",
".",
"AEAD",
"interface"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/aescbc/aescbc.go#L119-L143 |
21,235 | lestrrat-go/jwx | jwe/aescbc/aescbc.go | Open | func (c AesCbcHmac) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) {
if len(ciphertext) < c.keysize {
return nil, errors.New("invalid ciphertext (too short)")
}
tagOffset := len(ciphertext) - c.tagsize
if tagOffset%c.blockCipher.BlockSize() != 0 {
return nil, fmt.Errorf(
"invalid ciphertext (inva... | go | func (c AesCbcHmac) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) {
if len(ciphertext) < c.keysize {
return nil, errors.New("invalid ciphertext (too short)")
}
tagOffset := len(ciphertext) - c.tagsize
if tagOffset%c.blockCipher.BlockSize() != 0 {
return nil, fmt.Errorf(
"invalid ciphertext (inva... | [
"func",
"(",
"c",
"AesCbcHmac",
")",
"Open",
"(",
"dst",
",",
"nonce",
",",
"ciphertext",
",",
"data",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"len",
"(",
"ciphertext",
")",
"<",
"c",
".",
"keysize",
"{",
"re... | // Open fulfills the crypto.AEAD interface | [
"Open",
"fulfills",
"the",
"crypto",
".",
"AEAD",
"interface"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/aescbc/aescbc.go#L146-L183 |
21,236 | lestrrat-go/jwx | jwk/headers_gen.go | PopulateMap | func (h StandardHeaders) PopulateMap(m map[string]interface{}) error {
for k, v := range h.privateParams {
m[k] = v
}
if v, ok := h.Get(AlgorithmKey); ok {
m[AlgorithmKey] = v
}
if v, ok := h.Get(KeyIDKey); ok {
m[KeyIDKey] = v
}
if v, ok := h.Get(KeyTypeKey); ok {
m[KeyTypeKey] = v
}
if v, ok := h.Get... | go | func (h StandardHeaders) PopulateMap(m map[string]interface{}) error {
for k, v := range h.privateParams {
m[k] = v
}
if v, ok := h.Get(AlgorithmKey); ok {
m[AlgorithmKey] = v
}
if v, ok := h.Get(KeyIDKey); ok {
m[KeyIDKey] = v
}
if v, ok := h.Get(KeyTypeKey); ok {
m[KeyTypeKey] = v
}
if v, ok := h.Get... | [
"func",
"(",
"h",
"StandardHeaders",
")",
"PopulateMap",
"(",
"m",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"h",
".",
"privateParams",
"{",
"m",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
... | // PopulateMap populates a map with appropriate values that represent
// the headers as a JSON object. This exists primarily because JWKs are
// represented as flat objects instead of differentiating the different
// parts of the message in separate sub objects. | [
"PopulateMap",
"populates",
"a",
"map",
"with",
"appropriate",
"values",
"that",
"represent",
"the",
"headers",
"as",
"a",
"JSON",
"object",
".",
"This",
"exists",
"primarily",
"because",
"JWKs",
"are",
"represented",
"as",
"flat",
"objects",
"instead",
"of",
... | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwk/headers_gen.go#L254-L287 |
21,237 | lestrrat-go/jwx | jwe/encrypt.go | NewMultiEncrypt | func NewMultiEncrypt(cc ContentEncrypter, kg KeyGenerator, ke ...KeyEncrypter) *MultiEncrypt {
e := &MultiEncrypt{
ContentEncrypter: cc,
KeyGenerator: kg,
KeyEncrypters: ke,
}
return e
} | go | func NewMultiEncrypt(cc ContentEncrypter, kg KeyGenerator, ke ...KeyEncrypter) *MultiEncrypt {
e := &MultiEncrypt{
ContentEncrypter: cc,
KeyGenerator: kg,
KeyEncrypters: ke,
}
return e
} | [
"func",
"NewMultiEncrypt",
"(",
"cc",
"ContentEncrypter",
",",
"kg",
"KeyGenerator",
",",
"ke",
"...",
"KeyEncrypter",
")",
"*",
"MultiEncrypt",
"{",
"e",
":=",
"&",
"MultiEncrypt",
"{",
"ContentEncrypter",
":",
"cc",
",",
"KeyGenerator",
":",
"kg",
",",
"Ke... | // NewMultiEncrypt creates a new Encrypt struct. The caller is responsible
// for instantiating valid inputs for ContentEncrypter, KeyGenerator,
// and KeyEncrypters. | [
"NewMultiEncrypt",
"creates",
"a",
"new",
"Encrypt",
"struct",
".",
"The",
"caller",
"is",
"responsible",
"for",
"instantiating",
"valid",
"inputs",
"for",
"ContentEncrypter",
"KeyGenerator",
"and",
"KeyEncrypters",
"."
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/encrypt.go#L11-L18 |
21,238 | lestrrat-go/jwx | jwe/jwe.go | Decrypt | func Decrypt(buf []byte, alg jwa.KeyEncryptionAlgorithm, key interface{}) ([]byte, error) {
msg, err := Parse(buf)
if err != nil {
return nil, errors.Wrap(err, "failed to parse buffer for Decrypt")
}
return msg.Decrypt(alg, key)
} | go | func Decrypt(buf []byte, alg jwa.KeyEncryptionAlgorithm, key interface{}) ([]byte, error) {
msg, err := Parse(buf)
if err != nil {
return nil, errors.Wrap(err, "failed to parse buffer for Decrypt")
}
return msg.Decrypt(alg, key)
} | [
"func",
"Decrypt",
"(",
"buf",
"[",
"]",
"byte",
",",
"alg",
"jwa",
".",
"KeyEncryptionAlgorithm",
",",
"key",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"msg",
",",
"err",
":=",
"Parse",
"(",
"buf",
")",
"\n",
"if... | // Decrypt takes the key encryption algorithm and the corresponding
// key to decrypt the JWE message, and returns the decrypted payload.
// The JWE message can be either compact or full JSON format. | [
"Decrypt",
"takes",
"the",
"key",
"encryption",
"algorithm",
"and",
"the",
"corresponding",
"key",
"to",
"decrypt",
"the",
"JWE",
"message",
"and",
"returns",
"the",
"decrypted",
"payload",
".",
"The",
"JWE",
"message",
"can",
"be",
"either",
"compact",
"or",
... | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/jwe.go#L103-L110 |
21,239 | lestrrat-go/jwx | jwe/jwe.go | Parse | func Parse(buf []byte) (*Message, error) {
buf = bytes.TrimSpace(buf)
if len(buf) == 0 {
return nil, errors.New("empty buffer")
}
if buf[0] == '{' {
return parseJSON(buf)
}
return parseCompact(buf)
} | go | func Parse(buf []byte) (*Message, error) {
buf = bytes.TrimSpace(buf)
if len(buf) == 0 {
return nil, errors.New("empty buffer")
}
if buf[0] == '{' {
return parseJSON(buf)
}
return parseCompact(buf)
} | [
"func",
"Parse",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"*",
"Message",
",",
"error",
")",
"{",
"buf",
"=",
"bytes",
".",
"TrimSpace",
"(",
"buf",
")",
"\n",
"if",
"len",
"(",
"buf",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
... | // Parse parses the JWE message into a Message object. The JWE message
// can be either compact or full JSON format. | [
"Parse",
"parses",
"the",
"JWE",
"message",
"into",
"a",
"Message",
"object",
".",
"The",
"JWE",
"message",
"can",
"be",
"either",
"compact",
"or",
"full",
"JSON",
"format",
"."
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/jwe.go#L114-L124 |
21,240 | lestrrat-go/jwx | jwk/jwk.go | New | func New(key interface{}) (Key, error) {
if key == nil {
return nil, errors.New(`jwk.New requires a non-nil key`)
}
switch v := key.(type) {
case *rsa.PrivateKey:
return newRSAPrivateKey(v)
case *rsa.PublicKey:
return newRSAPublicKey(v)
case *ecdsa.PrivateKey:
return newECDSAPrivateKey(v)
case *ecdsa.Pu... | go | func New(key interface{}) (Key, error) {
if key == nil {
return nil, errors.New(`jwk.New requires a non-nil key`)
}
switch v := key.(type) {
case *rsa.PrivateKey:
return newRSAPrivateKey(v)
case *rsa.PublicKey:
return newRSAPublicKey(v)
case *ecdsa.PrivateKey:
return newECDSAPrivateKey(v)
case *ecdsa.Pu... | [
"func",
"New",
"(",
"key",
"interface",
"{",
"}",
")",
"(",
"Key",
",",
"error",
")",
"{",
"if",
"key",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"`jwk.New requires a non-nil key`",
")",
"\n",
"}",
"\n\n",
"switch",
"v",
":="... | // New creates a jwk.Key from the given key. | [
"New",
"creates",
"a",
"jwk",
".",
"Key",
"from",
"the",
"given",
"key",
"."
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwk/jwk.go#L49-L68 |
21,241 | lestrrat-go/jwx | jwk/jwk.go | Fetch | func Fetch(urlstring string, options ...Option) (*Set, error) {
u, err := url.Parse(urlstring)
if err != nil {
return nil, errors.Wrap(err, `failed to parse url`)
}
switch u.Scheme {
case "http", "https":
return FetchHTTP(urlstring, options...)
case "file":
f, err := os.Open(u.Path)
if err != nil {
re... | go | func Fetch(urlstring string, options ...Option) (*Set, error) {
u, err := url.Parse(urlstring)
if err != nil {
return nil, errors.Wrap(err, `failed to parse url`)
}
switch u.Scheme {
case "http", "https":
return FetchHTTP(urlstring, options...)
case "file":
f, err := os.Open(u.Path)
if err != nil {
re... | [
"func",
"Fetch",
"(",
"urlstring",
"string",
",",
"options",
"...",
"Option",
")",
"(",
"*",
"Set",
",",
"error",
")",
"{",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"urlstring",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"... | // Fetch fetches a JWK resource specified by a URL | [
"Fetch",
"fetches",
"a",
"JWK",
"resource",
"specified",
"by",
"a",
"URL"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwk/jwk.go#L71-L94 |
21,242 | lestrrat-go/jwx | jwk/jwk.go | FetchHTTP | func FetchHTTP(jwkurl string, options ...Option) (*Set, error) {
var httpcl HTTPClient = http.DefaultClient
for _, option := range options {
switch option.Name() {
case optkeyHTTPClient:
httpcl = option.Value().(HTTPClient)
}
}
res, err := httpcl.Get(jwkurl)
if err != nil {
return nil, errors.Wrap(err,... | go | func FetchHTTP(jwkurl string, options ...Option) (*Set, error) {
var httpcl HTTPClient = http.DefaultClient
for _, option := range options {
switch option.Name() {
case optkeyHTTPClient:
httpcl = option.Value().(HTTPClient)
}
}
res, err := httpcl.Get(jwkurl)
if err != nil {
return nil, errors.Wrap(err,... | [
"func",
"FetchHTTP",
"(",
"jwkurl",
"string",
",",
"options",
"...",
"Option",
")",
"(",
"*",
"Set",
",",
"error",
")",
"{",
"var",
"httpcl",
"HTTPClient",
"=",
"http",
".",
"DefaultClient",
"\n",
"for",
"_",
",",
"option",
":=",
"range",
"options",
"{... | // FetchHTTP fetches the remote JWK and parses its contents | [
"FetchHTTP",
"fetches",
"the",
"remote",
"JWK",
"and",
"parses",
"its",
"contents"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwk/jwk.go#L97-L122 |
21,243 | lestrrat-go/jwx | jwk/jwk.go | Parse | func Parse(in io.Reader) (*Set, error) {
m := make(map[string]interface{})
if err := json.NewDecoder(in).Decode(&m); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal JWK")
}
// We must change what the underlying structure that gets decoded
// out of this JSON is based on parameters within the alre... | go | func Parse(in io.Reader) (*Set, error) {
m := make(map[string]interface{})
if err := json.NewDecoder(in).Decode(&m); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal JWK")
}
// We must change what the underlying structure that gets decoded
// out of this JSON is based on parameters within the alre... | [
"func",
"Parse",
"(",
"in",
"io",
".",
"Reader",
")",
"(",
"*",
"Set",
",",
"error",
")",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"err",
":=",
"json",
".",
"NewDecoder",
"(",
"in",
")",
... | // Parse parses JWK from the incoming io.Reader. | [
"Parse",
"parses",
"JWK",
"from",
"the",
"incoming",
"io",
".",
"Reader",
"."
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwk/jwk.go#L134-L157 |
21,244 | lestrrat-go/jwx | jws/message.go | LookupSignature | func (m Message) LookupSignature(kid string) []*Signature {
var sigs []*Signature
for _, sig := range m.signatures {
if hdr := sig.PublicHeaders(); hdr != nil {
hdrKeyId, ok := hdr.Get(KeyIDKey)
if ok && hdrKeyId == kid {
sigs = append(sigs, sig)
continue
}
}
if hdr := sig.ProtectedHeaders(); ... | go | func (m Message) LookupSignature(kid string) []*Signature {
var sigs []*Signature
for _, sig := range m.signatures {
if hdr := sig.PublicHeaders(); hdr != nil {
hdrKeyId, ok := hdr.Get(KeyIDKey)
if ok && hdrKeyId == kid {
sigs = append(sigs, sig)
continue
}
}
if hdr := sig.ProtectedHeaders(); ... | [
"func",
"(",
"m",
"Message",
")",
"LookupSignature",
"(",
"kid",
"string",
")",
"[",
"]",
"*",
"Signature",
"{",
"var",
"sigs",
"[",
"]",
"*",
"Signature",
"\n",
"for",
"_",
",",
"sig",
":=",
"range",
"m",
".",
"signatures",
"{",
"if",
"hdr",
":=",... | // LookupSignature looks up a particular signature entry using
// the `kid` value | [
"LookupSignature",
"looks",
"up",
"a",
"particular",
"signature",
"entry",
"using",
"the",
"kid",
"value"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jws/message.go#L25-L45 |
21,245 | lestrrat-go/jwx | jwe/interface.go | NewErrUnsupportedAlgorithm | func NewErrUnsupportedAlgorithm(alg, purpose string) errUnsupportedAlgorithm {
return errUnsupportedAlgorithm{alg: alg, purpose: purpose}
} | go | func NewErrUnsupportedAlgorithm(alg, purpose string) errUnsupportedAlgorithm {
return errUnsupportedAlgorithm{alg: alg, purpose: purpose}
} | [
"func",
"NewErrUnsupportedAlgorithm",
"(",
"alg",
",",
"purpose",
"string",
")",
"errUnsupportedAlgorithm",
"{",
"return",
"errUnsupportedAlgorithm",
"{",
"alg",
":",
"alg",
",",
"purpose",
":",
"purpose",
"}",
"\n",
"}"
] | // NewErrUnsupportedAlgorithm creates a new UnsupportedAlgorithm error | [
"NewErrUnsupportedAlgorithm",
"creates",
"a",
"new",
"UnsupportedAlgorithm",
"error"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/interface.go#L31-L33 |
21,246 | lestrrat-go/jwx | jwe/interface.go | Error | func (e errUnsupportedAlgorithm) Error() string {
return fmt.Sprintf("unsupported algorithm '%s' for %s", e.alg, e.purpose)
} | go | func (e errUnsupportedAlgorithm) Error() string {
return fmt.Sprintf("unsupported algorithm '%s' for %s", e.alg, e.purpose)
} | [
"func",
"(",
"e",
"errUnsupportedAlgorithm",
")",
"Error",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"e",
".",
"alg",
",",
"e",
".",
"purpose",
")",
"\n",
"}"
] | // Error returns the string representation of the error | [
"Error",
"returns",
"the",
"string",
"representation",
"of",
"the",
"error"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/interface.go#L36-L38 |
21,247 | lestrrat-go/jwx | jws/jws.go | Sign | func Sign(payload []byte, alg jwa.SignatureAlgorithm, key interface{}, options ...Option) ([]byte, error) {
var hdrs Headers = &StandardHeaders{}
for _, o := range options {
switch o.Name() {
case optkeyHeaders:
hdrs = o.Value().(Headers)
}
}
signer, err := sign.New(alg)
if err != nil {
return nil, err... | go | func Sign(payload []byte, alg jwa.SignatureAlgorithm, key interface{}, options ...Option) ([]byte, error) {
var hdrs Headers = &StandardHeaders{}
for _, o := range options {
switch o.Name() {
case optkeyHeaders:
hdrs = o.Value().(Headers)
}
}
signer, err := sign.New(alg)
if err != nil {
return nil, err... | [
"func",
"Sign",
"(",
"payload",
"[",
"]",
"byte",
",",
"alg",
"jwa",
".",
"SignatureAlgorithm",
",",
"key",
"interface",
"{",
"}",
",",
"options",
"...",
"Option",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"hdrs",
"Headers",
"=",
"... | // Sign generates a signature for the given payload, and serializes
// it in compact serialization format. In this format you may NOT use
// multiple signers.
//
// If you would like to pass custom headers, use the WithHeaders option. | [
"Sign",
"generates",
"a",
"signature",
"for",
"the",
"given",
"payload",
"and",
"serializes",
"it",
"in",
"compact",
"serialization",
"format",
".",
"In",
"this",
"format",
"you",
"may",
"NOT",
"use",
"multiple",
"signers",
".",
"If",
"you",
"would",
"like",... | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jws/jws.go#L87-L141 |
21,248 | lestrrat-go/jwx | jws/jws.go | SignLiteral | func SignLiteral(payload []byte, alg jwa.SignatureAlgorithm, key interface{}, headers []byte) ([]byte, error) {
signer, err := sign.New(alg)
if err != nil {
return nil, errors.Wrap(err, `failed to create signer`)
}
var buf bytes.Buffer
enc := base64.NewEncoder(base64.RawURLEncoding, &buf)
if _, err := enc.Wri... | go | func SignLiteral(payload []byte, alg jwa.SignatureAlgorithm, key interface{}, headers []byte) ([]byte, error) {
signer, err := sign.New(alg)
if err != nil {
return nil, errors.Wrap(err, `failed to create signer`)
}
var buf bytes.Buffer
enc := base64.NewEncoder(base64.RawURLEncoding, &buf)
if _, err := enc.Wri... | [
"func",
"SignLiteral",
"(",
"payload",
"[",
"]",
"byte",
",",
"alg",
"jwa",
".",
"SignatureAlgorithm",
",",
"key",
"interface",
"{",
"}",
",",
"headers",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"signer",
",",
"err",
":... | // SignLiteral generates a signature for the given payload and headers, and serializes
// it in compact serialization format. In this format you may NOT use
// multiple signers.
// | [
"SignLiteral",
"generates",
"a",
"signature",
"for",
"the",
"given",
"payload",
"and",
"headers",
"and",
"serializes",
"it",
"in",
"compact",
"serialization",
"format",
".",
"In",
"this",
"format",
"you",
"may",
"NOT",
"use",
"multiple",
"signers",
"."
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jws/jws.go#L147-L187 |
21,249 | lestrrat-go/jwx | jws/jws.go | SignMulti | func SignMulti(payload []byte, options ...Option) ([]byte, error) {
var signers []PayloadSigner
for _, o := range options {
switch o.Name() {
case optkeyPayloadSigner:
signers = append(signers, o.Value().(PayloadSigner))
}
}
if len(signers) == 0 {
return nil, errors.New(`no signers provided`)
}
var r... | go | func SignMulti(payload []byte, options ...Option) ([]byte, error) {
var signers []PayloadSigner
for _, o := range options {
switch o.Name() {
case optkeyPayloadSigner:
signers = append(signers, o.Value().(PayloadSigner))
}
}
if len(signers) == 0 {
return nil, errors.New(`no signers provided`)
}
var r... | [
"func",
"SignMulti",
"(",
"payload",
"[",
"]",
"byte",
",",
"options",
"...",
"Option",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"signers",
"[",
"]",
"PayloadSigner",
"\n",
"for",
"_",
",",
"o",
":=",
"range",
"options",
"{",
"swi... | // SignMulti accepts multiple signers via the options parameter,
// and creates a JWS in JSON serialization format that contains
// signatures from applying aforementioned signers. | [
"SignMulti",
"accepts",
"multiple",
"signers",
"via",
"the",
"options",
"parameter",
"and",
"creates",
"a",
"JWS",
"in",
"JSON",
"serialization",
"format",
"that",
"contains",
"signatures",
"from",
"applying",
"aforementioned",
"signers",
"."
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jws/jws.go#L192-L239 |
21,250 | lestrrat-go/jwx | jws/jws.go | VerifyWithJKU | func VerifyWithJKU(buf []byte, jwkurl string) ([]byte, error) {
key, err := jwk.FetchHTTP(jwkurl)
if err != nil {
return nil, errors.Wrap(err, `failed to fetch jwk via HTTP`)
}
return VerifyWithJWKSet(buf, key, nil)
} | go | func VerifyWithJKU(buf []byte, jwkurl string) ([]byte, error) {
key, err := jwk.FetchHTTP(jwkurl)
if err != nil {
return nil, errors.Wrap(err, `failed to fetch jwk via HTTP`)
}
return VerifyWithJWKSet(buf, key, nil)
} | [
"func",
"VerifyWithJKU",
"(",
"buf",
"[",
"]",
"byte",
",",
"jwkurl",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"key",
",",
"err",
":=",
"jwk",
".",
"FetchHTTP",
"(",
"jwkurl",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return... | // VerifyWithJKU verifies the JWS message using a remote JWK
// file represented in the url. | [
"VerifyWithJKU",
"verifies",
"the",
"JWS",
"message",
"using",
"a",
"remote",
"JWK",
"file",
"represented",
"in",
"the",
"url",
"."
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jws/jws.go#L327-L334 |
21,251 | lestrrat-go/jwx | jws/jws.go | VerifyWithJWK | func VerifyWithJWK(buf []byte, key jwk.Key) (payload []byte, err error) {
keyval, err := key.Materialize()
if err != nil {
return nil, errors.Wrap(err, `failed to materialize jwk.Key`)
}
payload, err = Verify(buf, jwa.SignatureAlgorithm(key.Algorithm()), keyval)
if err != nil {
return nil, errors.Wrap(err, "... | go | func VerifyWithJWK(buf []byte, key jwk.Key) (payload []byte, err error) {
keyval, err := key.Materialize()
if err != nil {
return nil, errors.Wrap(err, `failed to materialize jwk.Key`)
}
payload, err = Verify(buf, jwa.SignatureAlgorithm(key.Algorithm()), keyval)
if err != nil {
return nil, errors.Wrap(err, "... | [
"func",
"VerifyWithJWK",
"(",
"buf",
"[",
"]",
"byte",
",",
"key",
"jwk",
".",
"Key",
")",
"(",
"payload",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"keyval",
",",
"err",
":=",
"key",
".",
"Materialize",
"(",
")",
"\n",
"if",
"err",
"!=",
... | // VerifyWithJWK verifies the JWS message using the specified JWK | [
"VerifyWithJWK",
"verifies",
"the",
"JWS",
"message",
"using",
"the",
"specified",
"JWK"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jws/jws.go#L337-L349 |
21,252 | lestrrat-go/jwx | jws/jws.go | VerifyWithJWKSet | func VerifyWithJWKSet(buf []byte, keyset *jwk.Set, keyaccept JWKAcceptFunc) (payload []byte, err error) {
if keyaccept == nil {
keyaccept = DefaultJWKAcceptor
}
for _, key := range keyset.Keys {
if !keyaccept(key) {
continue
}
payload, err := VerifyWithJWK(buf, key)
if err == nil {
return payload,... | go | func VerifyWithJWKSet(buf []byte, keyset *jwk.Set, keyaccept JWKAcceptFunc) (payload []byte, err error) {
if keyaccept == nil {
keyaccept = DefaultJWKAcceptor
}
for _, key := range keyset.Keys {
if !keyaccept(key) {
continue
}
payload, err := VerifyWithJWK(buf, key)
if err == nil {
return payload,... | [
"func",
"VerifyWithJWKSet",
"(",
"buf",
"[",
"]",
"byte",
",",
"keyset",
"*",
"jwk",
".",
"Set",
",",
"keyaccept",
"JWKAcceptFunc",
")",
"(",
"payload",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"if",
"keyaccept",
"==",
"nil",
"{",
"keyaccept",
... | // VerifyWithJWKSet verifies the JWS message using JWK key set.
// By default it will only pick up keys that have the "use" key
// set to either "sig" or "enc", but you can override it by
// providing a keyaccept function. | [
"VerifyWithJWKSet",
"verifies",
"the",
"JWS",
"message",
"using",
"JWK",
"key",
"set",
".",
"By",
"default",
"it",
"will",
"only",
"pick",
"up",
"keys",
"that",
"have",
"the",
"use",
"key",
"set",
"to",
"either",
"sig",
"or",
"enc",
"but",
"you",
"can",
... | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jws/jws.go#L355-L373 |
21,253 | lestrrat-go/jwx | jws/jws.go | Parse | func Parse(src io.Reader) (m *Message, err error) {
rdr := bufio.NewReader(src)
var first rune
for {
r, _, err := rdr.ReadRune()
if err != nil {
return nil, errors.Wrap(err, `failed to read rune`)
}
if !unicode.IsSpace(r) {
first = r
rdr.UnreadRune()
break
}
}
var parser func(io.Reader) (*M... | go | func Parse(src io.Reader) (m *Message, err error) {
rdr := bufio.NewReader(src)
var first rune
for {
r, _, err := rdr.ReadRune()
if err != nil {
return nil, errors.Wrap(err, `failed to read rune`)
}
if !unicode.IsSpace(r) {
first = r
rdr.UnreadRune()
break
}
}
var parser func(io.Reader) (*M... | [
"func",
"Parse",
"(",
"src",
"io",
".",
"Reader",
")",
"(",
"m",
"*",
"Message",
",",
"err",
"error",
")",
"{",
"rdr",
":=",
"bufio",
".",
"NewReader",
"(",
"src",
")",
"\n",
"var",
"first",
"rune",
"\n",
"for",
"{",
"r",
",",
"_",
",",
"err",
... | // Parse parses contents from the given source and creates a jws.Message
// struct. The input can be in either compact or full JSON serialization. | [
"Parse",
"parses",
"contents",
"from",
"the",
"given",
"source",
"and",
"creates",
"a",
"jws",
".",
"Message",
"struct",
".",
"The",
"input",
"can",
"be",
"in",
"either",
"compact",
"or",
"full",
"JSON",
"serialization",
"."
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jws/jws.go#L377-L406 |
21,254 | lestrrat-go/jwx | jws/jws.go | parseCompact | func parseCompact(rdr io.Reader) (m *Message, err error) {
protected, payload, signature, err := SplitCompact(rdr)
if err != nil {
return nil, errors.Wrap(err, `invalid compact serialization format`)
}
decodedHeader := make([]byte, base64.RawURLEncoding.DecodedLen(len(protected)))
if _, err := base64.RawURLEnc... | go | func parseCompact(rdr io.Reader) (m *Message, err error) {
protected, payload, signature, err := SplitCompact(rdr)
if err != nil {
return nil, errors.Wrap(err, `invalid compact serialization format`)
}
decodedHeader := make([]byte, base64.RawURLEncoding.DecodedLen(len(protected)))
if _, err := base64.RawURLEnc... | [
"func",
"parseCompact",
"(",
"rdr",
"io",
".",
"Reader",
")",
"(",
"m",
"*",
"Message",
",",
"err",
"error",
")",
"{",
"protected",
",",
"payload",
",",
"signature",
",",
"err",
":=",
"SplitCompact",
"(",
"rdr",
")",
"\n",
"if",
"err",
"!=",
"nil",
... | // parseCompact parses a JWS value serialized via compact serialization. | [
"parseCompact",
"parses",
"a",
"JWS",
"value",
"serialized",
"via",
"compact",
"serialization",
"."
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jws/jws.go#L525-L558 |
21,255 | lestrrat-go/jwx | jws/verify/verify.go | New | func New(alg jwa.SignatureAlgorithm) (Verifier, error) {
switch alg {
case jwa.RS256, jwa.RS384, jwa.RS512, jwa.PS256, jwa.PS384, jwa.PS512:
return newRSA(alg)
case jwa.ES256, jwa.ES384, jwa.ES512:
return newECDSA(alg)
case jwa.HS256, jwa.HS384, jwa.HS512:
return newHMAC(alg)
default:
return nil, errors.Er... | go | func New(alg jwa.SignatureAlgorithm) (Verifier, error) {
switch alg {
case jwa.RS256, jwa.RS384, jwa.RS512, jwa.PS256, jwa.PS384, jwa.PS512:
return newRSA(alg)
case jwa.ES256, jwa.ES384, jwa.ES512:
return newECDSA(alg)
case jwa.HS256, jwa.HS384, jwa.HS512:
return newHMAC(alg)
default:
return nil, errors.Er... | [
"func",
"New",
"(",
"alg",
"jwa",
".",
"SignatureAlgorithm",
")",
"(",
"Verifier",
",",
"error",
")",
"{",
"switch",
"alg",
"{",
"case",
"jwa",
".",
"RS256",
",",
"jwa",
".",
"RS384",
",",
"jwa",
".",
"RS512",
",",
"jwa",
".",
"PS256",
",",
"jwa",
... | // New creates a new JWS verifier using the specified algorithm
// and the public key | [
"New",
"creates",
"a",
"new",
"JWS",
"verifier",
"using",
"the",
"specified",
"algorithm",
"and",
"the",
"public",
"key"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jws/verify/verify.go#L10-L21 |
21,256 | lestrrat-go/jwx | jwt/jwt.go | ParseString | func ParseString(s string, options ...Option) (*Token, error) {
return Parse(strings.NewReader(s), options...)
} | go | func ParseString(s string, options ...Option) (*Token, error) {
return Parse(strings.NewReader(s), options...)
} | [
"func",
"ParseString",
"(",
"s",
"string",
",",
"options",
"...",
"Option",
")",
"(",
"*",
"Token",
",",
"error",
")",
"{",
"return",
"Parse",
"(",
"strings",
".",
"NewReader",
"(",
"s",
")",
",",
"options",
"...",
")",
"\n",
"}"
] | // ParseString calls Parse with the given string | [
"ParseString",
"calls",
"Parse",
"with",
"the",
"given",
"string"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwt/jwt.go#L19-L21 |
21,257 | lestrrat-go/jwx | jwt/jwt.go | ParseBytes | func ParseBytes(s []byte, options ...Option) (*Token, error) {
return Parse(bytes.NewReader(s), options...)
} | go | func ParseBytes(s []byte, options ...Option) (*Token, error) {
return Parse(bytes.NewReader(s), options...)
} | [
"func",
"ParseBytes",
"(",
"s",
"[",
"]",
"byte",
",",
"options",
"...",
"Option",
")",
"(",
"*",
"Token",
",",
"error",
")",
"{",
"return",
"Parse",
"(",
"bytes",
".",
"NewReader",
"(",
"s",
")",
",",
"options",
"...",
")",
"\n",
"}"
] | // ParseString calls Parse with the given byte sequence | [
"ParseString",
"calls",
"Parse",
"with",
"the",
"given",
"byte",
"sequence"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwt/jwt.go#L24-L26 |
21,258 | lestrrat-go/jwx | jwt/jwt.go | Sign | func (t *Token) Sign(method jwa.SignatureAlgorithm, key interface{}) ([]byte, error) {
buf, err := json.Marshal(t)
if err != nil {
return nil, errors.Wrap(err, `failed to marshal token`)
}
var hdr jws.StandardHeaders
if hdr.Set(`alg`, method.String()) != nil {
return nil, errors.Wrap(err, `failed to sign payl... | go | func (t *Token) Sign(method jwa.SignatureAlgorithm, key interface{}) ([]byte, error) {
buf, err := json.Marshal(t)
if err != nil {
return nil, errors.Wrap(err, `failed to marshal token`)
}
var hdr jws.StandardHeaders
if hdr.Set(`alg`, method.String()) != nil {
return nil, errors.Wrap(err, `failed to sign payl... | [
"func",
"(",
"t",
"*",
"Token",
")",
"Sign",
"(",
"method",
"jwa",
".",
"SignatureAlgorithm",
",",
"key",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"buf",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"t",
")",
... | // Sign is a convenience function to create a signed JWT token serialized in
// compact form. `key` must match the key type required by the given
// signature method `method` | [
"Sign",
"is",
"a",
"convenience",
"function",
"to",
"create",
"a",
"signed",
"JWT",
"token",
"serialized",
"in",
"compact",
"form",
".",
"key",
"must",
"match",
"the",
"key",
"type",
"required",
"by",
"the",
"given",
"signature",
"method",
"method"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwt/jwt.go#L87-L106 |
21,259 | lestrrat-go/jwx | buffer/buffer.go | FromUint | func FromUint(v uint64) Buffer {
data := make([]byte, 8)
binary.BigEndian.PutUint64(data, v)
i := 0
for ; i < len(data); i++ {
if data[i] != 0x0 {
break
}
}
return Buffer(data[i:])
} | go | func FromUint(v uint64) Buffer {
data := make([]byte, 8)
binary.BigEndian.PutUint64(data, v)
i := 0
for ; i < len(data); i++ {
if data[i] != 0x0 {
break
}
}
return Buffer(data[i:])
} | [
"func",
"FromUint",
"(",
"v",
"uint64",
")",
"Buffer",
"{",
"data",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"8",
")",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint64",
"(",
"data",
",",
"v",
")",
"\n\n",
"i",
":=",
"0",
"\n",
"for",
";",
"i... | // FromUint creates a `Buffer` from an unsigned int | [
"FromUint",
"creates",
"a",
"Buffer",
"from",
"an",
"unsigned",
"int"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/buffer/buffer.go#L21-L32 |
21,260 | lestrrat-go/jwx | buffer/buffer.go | FromBase64 | func FromBase64(v []byte) (Buffer, error) {
b := Buffer{}
if err := b.Base64Decode(v); err != nil {
return Buffer(nil), errors.Wrap(err, "failed to decode from base64")
}
return b, nil
} | go | func FromBase64(v []byte) (Buffer, error) {
b := Buffer{}
if err := b.Base64Decode(v); err != nil {
return Buffer(nil), errors.Wrap(err, "failed to decode from base64")
}
return b, nil
} | [
"func",
"FromBase64",
"(",
"v",
"[",
"]",
"byte",
")",
"(",
"Buffer",
",",
"error",
")",
"{",
"b",
":=",
"Buffer",
"{",
"}",
"\n",
"if",
"err",
":=",
"b",
".",
"Base64Decode",
"(",
"v",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"Buffer",
"("... | // FromBase64 constructs a new Buffer from a base64 encoded data | [
"FromBase64",
"constructs",
"a",
"new",
"Buffer",
"from",
"a",
"base64",
"encoded",
"data"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/buffer/buffer.go#L35-L42 |
21,261 | lestrrat-go/jwx | buffer/buffer.go | NData | func (b Buffer) NData() []byte {
buf := make([]byte, 4+b.Len())
binary.BigEndian.PutUint32(buf, uint32(b.Len()))
copy(buf[4:], b.Bytes())
return buf
} | go | func (b Buffer) NData() []byte {
buf := make([]byte, 4+b.Len())
binary.BigEndian.PutUint32(buf, uint32(b.Len()))
copy(buf[4:], b.Bytes())
return buf
} | [
"func",
"(",
"b",
"Buffer",
")",
"NData",
"(",
")",
"[",
"]",
"byte",
"{",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"4",
"+",
"b",
".",
"Len",
"(",
")",
")",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint32",
"(",
"buf",
",",
"uint32... | // NData returns Datalen || Data, where Datalen is a 32 bit counter for
// the length of the following data, and Data is the octets that comprise
// the buffer data | [
"NData",
"returns",
"Datalen",
"||",
"Data",
"where",
"Datalen",
"is",
"a",
"32",
"bit",
"counter",
"for",
"the",
"length",
"of",
"the",
"following",
"data",
"and",
"Data",
"is",
"the",
"octets",
"that",
"comprise",
"the",
"buffer",
"data"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/buffer/buffer.go#L61-L67 |
21,262 | lestrrat-go/jwx | buffer/buffer.go | Base64Encode | func (b Buffer) Base64Encode() ([]byte, error) {
enc := base64.RawURLEncoding
out := make([]byte, enc.EncodedLen(len(b)))
enc.Encode(out, b)
return out, nil
} | go | func (b Buffer) Base64Encode() ([]byte, error) {
enc := base64.RawURLEncoding
out := make([]byte, enc.EncodedLen(len(b)))
enc.Encode(out, b)
return out, nil
} | [
"func",
"(",
"b",
"Buffer",
")",
"Base64Encode",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"enc",
":=",
"base64",
".",
"RawURLEncoding",
"\n",
"out",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"enc",
".",
"EncodedLen",
"(",
"len",
"... | // Base64Encode encodes the contents of the Buffer using base64.RawURLEncoding | [
"Base64Encode",
"encodes",
"the",
"contents",
"of",
"the",
"Buffer",
"using",
"base64",
".",
"RawURLEncoding"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/buffer/buffer.go#L80-L85 |
21,263 | lestrrat-go/jwx | buffer/buffer.go | Base64Decode | func (b *Buffer) Base64Decode(v []byte) error {
enc := base64.RawURLEncoding
out := make([]byte, enc.DecodedLen(len(v)))
n, err := enc.Decode(out, v)
if err != nil {
return errors.Wrap(err, "failed to decode from base64")
}
out = out[:n]
*b = Buffer(out)
return nil
} | go | func (b *Buffer) Base64Decode(v []byte) error {
enc := base64.RawURLEncoding
out := make([]byte, enc.DecodedLen(len(v)))
n, err := enc.Decode(out, v)
if err != nil {
return errors.Wrap(err, "failed to decode from base64")
}
out = out[:n]
*b = Buffer(out)
return nil
} | [
"func",
"(",
"b",
"*",
"Buffer",
")",
"Base64Decode",
"(",
"v",
"[",
"]",
"byte",
")",
"error",
"{",
"enc",
":=",
"base64",
".",
"RawURLEncoding",
"\n",
"out",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"enc",
".",
"DecodedLen",
"(",
"len",
"(",
"... | // Base64Decode decodes the contents of the Buffer using base64.RawURLEncoding | [
"Base64Decode",
"decodes",
"the",
"contents",
"of",
"the",
"Buffer",
"using",
"base64",
".",
"RawURLEncoding"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/buffer/buffer.go#L88-L98 |
21,264 | lestrrat-go/jwx | buffer/buffer.go | MarshalJSON | func (b Buffer) MarshalJSON() ([]byte, error) {
v, err := b.Base64Encode()
if err != nil {
return nil, errors.Wrap(err, "failed to encode to base64")
}
return json.Marshal(string(v))
} | go | func (b Buffer) MarshalJSON() ([]byte, error) {
v, err := b.Base64Encode()
if err != nil {
return nil, errors.Wrap(err, "failed to encode to base64")
}
return json.Marshal(string(v))
} | [
"func",
"(",
"b",
"Buffer",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"b",
".",
"Base64Encode",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap"... | // MarshalJSON marshals the buffer into JSON format after encoding the buffer
// with base64.RawURLEncoding | [
"MarshalJSON",
"marshals",
"the",
"buffer",
"into",
"JSON",
"format",
"after",
"encoding",
"the",
"buffer",
"with",
"base64",
".",
"RawURLEncoding"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/buffer/buffer.go#L102-L108 |
21,265 | lestrrat-go/jwx | buffer/buffer.go | UnmarshalJSON | func (b *Buffer) UnmarshalJSON(data []byte) error {
var x string
if err := json.Unmarshal(data, &x); err != nil {
return errors.Wrap(err, "failed to unmarshal JSON")
}
return b.Base64Decode([]byte(x))
} | go | func (b *Buffer) UnmarshalJSON(data []byte) error {
var x string
if err := json.Unmarshal(data, &x); err != nil {
return errors.Wrap(err, "failed to unmarshal JSON")
}
return b.Base64Decode([]byte(x))
} | [
"func",
"(",
"b",
"*",
"Buffer",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"x",
"string",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"x",
")",
";",
"err",
"!=",
"nil",
"{",
"re... | // UnmarshalJSON unmarshals from a JSON string into a Buffer, after decoding it
// with base64.RawURLEncoding | [
"UnmarshalJSON",
"unmarshals",
"from",
"a",
"JSON",
"string",
"into",
"a",
"Buffer",
"after",
"decoding",
"it",
"with",
"base64",
".",
"RawURLEncoding"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/buffer/buffer.go#L112-L118 |
21,266 | lestrrat-go/jwx | jwe/key_generate.go | KeyGenerate | func (g StaticKeyGenerate) KeyGenerate() (ByteSource, error) {
buf := make([]byte, g.KeySize())
copy(buf, g)
return ByteKey(buf), nil
} | go | func (g StaticKeyGenerate) KeyGenerate() (ByteSource, error) {
buf := make([]byte, g.KeySize())
copy(buf, g)
return ByteKey(buf), nil
} | [
"func",
"(",
"g",
"StaticKeyGenerate",
")",
"KeyGenerate",
"(",
")",
"(",
"ByteSource",
",",
"error",
")",
"{",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"g",
".",
"KeySize",
"(",
")",
")",
"\n",
"copy",
"(",
"buf",
",",
"g",
")",
"\n",
... | // KeyGenerate returns the key | [
"KeyGenerate",
"returns",
"the",
"key"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/key_generate.go#L27-L31 |
21,267 | lestrrat-go/jwx | jwe/key_generate.go | KeyGenerate | func (g RandomKeyGenerate) KeyGenerate() (ByteSource, error) {
buf := make([]byte, g.keysize)
if _, err := io.ReadFull(rand.Reader, buf); err != nil {
return nil, errors.Wrap(err, "failed to read from rand.Reader")
}
return ByteKey(buf), nil
} | go | func (g RandomKeyGenerate) KeyGenerate() (ByteSource, error) {
buf := make([]byte, g.keysize)
if _, err := io.ReadFull(rand.Reader, buf); err != nil {
return nil, errors.Wrap(err, "failed to read from rand.Reader")
}
return ByteKey(buf), nil
} | [
"func",
"(",
"g",
"RandomKeyGenerate",
")",
"KeyGenerate",
"(",
")",
"(",
"ByteSource",
",",
"error",
")",
"{",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"g",
".",
"keysize",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"ReadFull",
"... | // KeyGenerate generates a random new key | [
"KeyGenerate",
"generates",
"a",
"random",
"new",
"key"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/key_generate.go#L45-L51 |
21,268 | lestrrat-go/jwx | jwe/key_generate.go | NewEcdhesKeyGenerate | func NewEcdhesKeyGenerate(alg jwa.KeyEncryptionAlgorithm, pubkey *ecdsa.PublicKey) (*EcdhesKeyGenerate, error) {
var keysize int
switch alg {
case jwa.ECDH_ES:
return nil, errors.New("unimplemented")
case jwa.ECDH_ES_A128KW:
keysize = 16
case jwa.ECDH_ES_A192KW:
keysize = 24
case jwa.ECDH_ES_A256KW:
keysi... | go | func NewEcdhesKeyGenerate(alg jwa.KeyEncryptionAlgorithm, pubkey *ecdsa.PublicKey) (*EcdhesKeyGenerate, error) {
var keysize int
switch alg {
case jwa.ECDH_ES:
return nil, errors.New("unimplemented")
case jwa.ECDH_ES_A128KW:
keysize = 16
case jwa.ECDH_ES_A192KW:
keysize = 24
case jwa.ECDH_ES_A256KW:
keysi... | [
"func",
"NewEcdhesKeyGenerate",
"(",
"alg",
"jwa",
".",
"KeyEncryptionAlgorithm",
",",
"pubkey",
"*",
"ecdsa",
".",
"PublicKey",
")",
"(",
"*",
"EcdhesKeyGenerate",
",",
"error",
")",
"{",
"var",
"keysize",
"int",
"\n",
"switch",
"alg",
"{",
"case",
"jwa",
... | // NewEcdhesKeyGenerate creates a new key generator using ECDH-ES | [
"NewEcdhesKeyGenerate",
"creates",
"a",
"new",
"key",
"generator",
"using",
"ECDH",
"-",
"ES"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/key_generate.go#L54-L74 |
21,269 | lestrrat-go/jwx | jwe/key_generate.go | KeyGenerate | func (g EcdhesKeyGenerate) KeyGenerate() (ByteSource, error) {
priv, err := ecdsa.GenerateKey(g.pubkey.Curve, rand.Reader)
if err != nil {
return nil, errors.Wrap(err, "failed to generate key for ECDH-ES")
}
pubinfo := make([]byte, 4)
binary.BigEndian.PutUint32(pubinfo, uint32(g.keysize)*8)
z, _ := priv.Publi... | go | func (g EcdhesKeyGenerate) KeyGenerate() (ByteSource, error) {
priv, err := ecdsa.GenerateKey(g.pubkey.Curve, rand.Reader)
if err != nil {
return nil, errors.Wrap(err, "failed to generate key for ECDH-ES")
}
pubinfo := make([]byte, 4)
binary.BigEndian.PutUint32(pubinfo, uint32(g.keysize)*8)
z, _ := priv.Publi... | [
"func",
"(",
"g",
"EcdhesKeyGenerate",
")",
"KeyGenerate",
"(",
")",
"(",
"ByteSource",
",",
"error",
")",
"{",
"priv",
",",
"err",
":=",
"ecdsa",
".",
"GenerateKey",
"(",
"g",
".",
"pubkey",
".",
"Curve",
",",
"rand",
".",
"Reader",
")",
"\n",
"if",... | // KeyGenerate generates new keys using ECDH-ES | [
"KeyGenerate",
"generates",
"new",
"keys",
"using",
"ECDH",
"-",
"ES"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/key_generate.go#L82-L100 |
21,270 | lestrrat-go/jwx | jwe/message.go | Get | func (h *Header) Get(key string) (interface{}, error) {
switch key {
case "alg":
return h.Algorithm, nil
case "apu":
return h.AgreementPartyUInfo, nil
case "apv":
return h.AgreementPartyVInfo, nil
case "enc":
return h.ContentEncryption, nil
case "epk":
return h.EphemeralPublicKey, nil
case "cty":
ret... | go | func (h *Header) Get(key string) (interface{}, error) {
switch key {
case "alg":
return h.Algorithm, nil
case "apu":
return h.AgreementPartyUInfo, nil
case "apv":
return h.AgreementPartyVInfo, nil
case "enc":
return h.ContentEncryption, nil
case "epk":
return h.EphemeralPublicKey, nil
case "cty":
ret... | [
"func",
"(",
"h",
"*",
"Header",
")",
"Get",
"(",
"key",
"string",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"switch",
"key",
"{",
"case",
"\"",
"\"",
":",
"return",
"h",
".",
"Algorithm",
",",
"nil",
"\n",
"case",
"\"",
"\"",
":... | // Get returns the header key | [
"Get",
"returns",
"the",
"header",
"key"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/message.go#L39-L76 |
21,271 | lestrrat-go/jwx | jwe/message.go | Base64Encode | func (e EncodedHeader) Base64Encode() ([]byte, error) {
buf, err := json.Marshal(e.Header)
if err != nil {
return nil, errors.Wrap(err, "failed to marshal encoded header into JSON")
}
buf, err = buffer.Buffer(buf).Base64Encode()
if err != nil {
return nil, errors.Wrap(err, "failed to base64 encode encoded hea... | go | func (e EncodedHeader) Base64Encode() ([]byte, error) {
buf, err := json.Marshal(e.Header)
if err != nil {
return nil, errors.Wrap(err, "failed to marshal encoded header into JSON")
}
buf, err = buffer.Buffer(buf).Base64Encode()
if err != nil {
return nil, errors.Wrap(err, "failed to base64 encode encoded hea... | [
"func",
"(",
"e",
"EncodedHeader",
")",
"Base64Encode",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"buf",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"e",
".",
"Header",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
... | // Base64Encode creates the base64 encoded version of the JSON
// representation of this header | [
"Base64Encode",
"creates",
"the",
"base64",
"encoded",
"version",
"of",
"the",
"JSON",
"representation",
"of",
"this",
"header"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/message.go#L395-L407 |
21,272 | lestrrat-go/jwx | jwt/token_gen.go | UnmarshalJSON | func (t *Token) UnmarshalJSON(data []byte) error {
var m map[string]interface{}
if err := json.Unmarshal(data, &m); err != nil {
return errors.Wrap(err, `failed to unmarshal token`)
}
for name, value := range m {
if err := t.Set(name, value); err != nil {
return errors.Wrapf(err, `failed to set value for %s`... | go | func (t *Token) UnmarshalJSON(data []byte) error {
var m map[string]interface{}
if err := json.Unmarshal(data, &m); err != nil {
return errors.Wrap(err, `failed to unmarshal token`)
}
for name, value := range m {
if err := t.Set(name, value); err != nil {
return errors.Wrapf(err, `failed to set value for %s`... | [
"func",
"(",
"t",
"*",
"Token",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"m",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"m",
... | // UnmarshalJSON deserializes data from a JSON data buffer into a Token | [
"UnmarshalJSON",
"deserializes",
"data",
"from",
"a",
"JSON",
"data",
"buffer",
"into",
"a",
"Token"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwt/token_gen.go#L311-L322 |
21,273 | lestrrat-go/jwx | jwe/key_encrypt.go | NewKeyWrapEncrypt | func NewKeyWrapEncrypt(alg jwa.KeyEncryptionAlgorithm, sharedkey []byte) (KeyWrapEncrypt, error) {
return KeyWrapEncrypt{
alg: alg,
sharedkey: sharedkey,
}, nil
} | go | func NewKeyWrapEncrypt(alg jwa.KeyEncryptionAlgorithm, sharedkey []byte) (KeyWrapEncrypt, error) {
return KeyWrapEncrypt{
alg: alg,
sharedkey: sharedkey,
}, nil
} | [
"func",
"NewKeyWrapEncrypt",
"(",
"alg",
"jwa",
".",
"KeyEncryptionAlgorithm",
",",
"sharedkey",
"[",
"]",
"byte",
")",
"(",
"KeyWrapEncrypt",
",",
"error",
")",
"{",
"return",
"KeyWrapEncrypt",
"{",
"alg",
":",
"alg",
",",
"sharedkey",
":",
"sharedkey",
","... | // NewKeyWrapEncrypt creates a key-wrap encrypter using AES-CGM.
// Although the name suggests otherwise, this does the decryption as well. | [
"NewKeyWrapEncrypt",
"creates",
"a",
"key",
"-",
"wrap",
"encrypter",
"using",
"AES",
"-",
"CGM",
".",
"Although",
"the",
"name",
"suggests",
"otherwise",
"this",
"does",
"the",
"decryption",
"as",
"well",
"."
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/key_encrypt.go#L25-L30 |
21,274 | lestrrat-go/jwx | jwe/key_encrypt.go | KeyDecrypt | func (kw KeyWrapEncrypt) KeyDecrypt(enckey []byte) ([]byte, error) {
block, err := aes.NewCipher(kw.sharedkey)
if err != nil {
return nil, errors.Wrap(err, "failed to create cipher from shared key")
}
cek, err := keyunwrap(block, enckey)
if err != nil {
return nil, errors.Wrap(err, "failed to unwrap data")
}... | go | func (kw KeyWrapEncrypt) KeyDecrypt(enckey []byte) ([]byte, error) {
block, err := aes.NewCipher(kw.sharedkey)
if err != nil {
return nil, errors.Wrap(err, "failed to create cipher from shared key")
}
cek, err := keyunwrap(block, enckey)
if err != nil {
return nil, errors.Wrap(err, "failed to unwrap data")
}... | [
"func",
"(",
"kw",
"KeyWrapEncrypt",
")",
"KeyDecrypt",
"(",
"enckey",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"block",
",",
"err",
":=",
"aes",
".",
"NewCipher",
"(",
"kw",
".",
"sharedkey",
")",
"\n",
"if",
"err",
... | // KeyDecrypt decrypts the encrypted key using AES-CGM key unwrap | [
"KeyDecrypt",
"decrypts",
"the",
"encrypted",
"key",
"using",
"AES",
"-",
"CGM",
"key",
"unwrap"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/key_encrypt.go#L43-L54 |
21,275 | lestrrat-go/jwx | jwe/key_encrypt.go | KeyEncrypt | func (kw KeyWrapEncrypt) KeyEncrypt(cek []byte) (ByteSource, error) {
block, err := aes.NewCipher(kw.sharedkey)
if err != nil {
return nil, errors.Wrap(err, "failed to create cipher from shared key")
}
encrypted, err := keywrap(block, cek)
if err != nil {
return nil, errors.Wrap(err, `keywrap: failed to wrap k... | go | func (kw KeyWrapEncrypt) KeyEncrypt(cek []byte) (ByteSource, error) {
block, err := aes.NewCipher(kw.sharedkey)
if err != nil {
return nil, errors.Wrap(err, "failed to create cipher from shared key")
}
encrypted, err := keywrap(block, cek)
if err != nil {
return nil, errors.Wrap(err, `keywrap: failed to wrap k... | [
"func",
"(",
"kw",
"KeyWrapEncrypt",
")",
"KeyEncrypt",
"(",
"cek",
"[",
"]",
"byte",
")",
"(",
"ByteSource",
",",
"error",
")",
"{",
"block",
",",
"err",
":=",
"aes",
".",
"NewCipher",
"(",
"kw",
".",
"sharedkey",
")",
"\n",
"if",
"err",
"!=",
"ni... | // KeyEncrypt encrypts the given content encryption key | [
"KeyEncrypt",
"encrypts",
"the",
"given",
"content",
"encryption",
"key"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/key_encrypt.go#L57-L67 |
21,276 | lestrrat-go/jwx | jwe/key_encrypt.go | NewEcdhesKeyWrapEncrypt | func NewEcdhesKeyWrapEncrypt(alg jwa.KeyEncryptionAlgorithm, key *ecdsa.PublicKey) (*EcdhesKeyWrapEncrypt, error) {
generator, err := NewEcdhesKeyGenerate(alg, key)
if err != nil {
return nil, errors.Wrap(err, "failed to create key generator")
}
return &EcdhesKeyWrapEncrypt{
algorithm: alg,
generator: generat... | go | func NewEcdhesKeyWrapEncrypt(alg jwa.KeyEncryptionAlgorithm, key *ecdsa.PublicKey) (*EcdhesKeyWrapEncrypt, error) {
generator, err := NewEcdhesKeyGenerate(alg, key)
if err != nil {
return nil, errors.Wrap(err, "failed to create key generator")
}
return &EcdhesKeyWrapEncrypt{
algorithm: alg,
generator: generat... | [
"func",
"NewEcdhesKeyWrapEncrypt",
"(",
"alg",
"jwa",
".",
"KeyEncryptionAlgorithm",
",",
"key",
"*",
"ecdsa",
".",
"PublicKey",
")",
"(",
"*",
"EcdhesKeyWrapEncrypt",
",",
"error",
")",
"{",
"generator",
",",
"err",
":=",
"NewEcdhesKeyGenerate",
"(",
"alg",
"... | // NewEcdhesKeyWrapEncrypt creates a new key encrypter based on ECDH-ES | [
"NewEcdhesKeyWrapEncrypt",
"creates",
"a",
"new",
"key",
"encrypter",
"based",
"on",
"ECDH",
"-",
"ES"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/key_encrypt.go#L70-L79 |
21,277 | lestrrat-go/jwx | jwe/key_encrypt.go | KeyEncrypt | func (kw EcdhesKeyWrapEncrypt) KeyEncrypt(cek []byte) (ByteSource, error) {
kg, err := kw.generator.KeyGenerate()
if err != nil {
return nil, errors.Wrap(err, "failed to create key generator")
}
bwpk, ok := kg.(ByteWithECPrivateKey)
if !ok {
return nil, errors.New("key generator generated invalid key (expecte... | go | func (kw EcdhesKeyWrapEncrypt) KeyEncrypt(cek []byte) (ByteSource, error) {
kg, err := kw.generator.KeyGenerate()
if err != nil {
return nil, errors.Wrap(err, "failed to create key generator")
}
bwpk, ok := kg.(ByteWithECPrivateKey)
if !ok {
return nil, errors.New("key generator generated invalid key (expecte... | [
"func",
"(",
"kw",
"EcdhesKeyWrapEncrypt",
")",
"KeyEncrypt",
"(",
"cek",
"[",
"]",
"byte",
")",
"(",
"ByteSource",
",",
"error",
")",
"{",
"kg",
",",
"err",
":=",
"kw",
".",
"generator",
".",
"KeyGenerate",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
... | // KeyEncrypt encrypts the content encryption key using ECDH-ES | [
"KeyEncrypt",
"encrypts",
"the",
"content",
"encryption",
"key",
"using",
"ECDH",
"-",
"ES"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/key_encrypt.go#L92-L116 |
21,278 | lestrrat-go/jwx | jwe/key_encrypt.go | NewEcdhesKeyWrapDecrypt | func NewEcdhesKeyWrapDecrypt(alg jwa.KeyEncryptionAlgorithm, pubkey *ecdsa.PublicKey, apu, apv []byte, privkey *ecdsa.PrivateKey) *EcdhesKeyWrapDecrypt {
return &EcdhesKeyWrapDecrypt{
algorithm: alg,
apu: apu,
apv: apv,
privkey: privkey,
pubkey: pubkey,
}
} | go | func NewEcdhesKeyWrapDecrypt(alg jwa.KeyEncryptionAlgorithm, pubkey *ecdsa.PublicKey, apu, apv []byte, privkey *ecdsa.PrivateKey) *EcdhesKeyWrapDecrypt {
return &EcdhesKeyWrapDecrypt{
algorithm: alg,
apu: apu,
apv: apv,
privkey: privkey,
pubkey: pubkey,
}
} | [
"func",
"NewEcdhesKeyWrapDecrypt",
"(",
"alg",
"jwa",
".",
"KeyEncryptionAlgorithm",
",",
"pubkey",
"*",
"ecdsa",
".",
"PublicKey",
",",
"apu",
",",
"apv",
"[",
"]",
"byte",
",",
"privkey",
"*",
"ecdsa",
".",
"PrivateKey",
")",
"*",
"EcdhesKeyWrapDecrypt",
"... | // NewEcdhesKeyWrapDecrypt creates a new key decrypter using ECDH-ES | [
"NewEcdhesKeyWrapDecrypt",
"creates",
"a",
"new",
"key",
"decrypter",
"using",
"ECDH",
"-",
"ES"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/key_encrypt.go#L119-L127 |
21,279 | lestrrat-go/jwx | jwe/key_encrypt.go | KeyDecrypt | func (kw EcdhesKeyWrapDecrypt) KeyDecrypt(enckey []byte) ([]byte, error) {
var keysize uint32
switch kw.algorithm {
case jwa.ECDH_ES_A128KW:
keysize = 16
case jwa.ECDH_ES_A192KW:
keysize = 24
case jwa.ECDH_ES_A256KW:
keysize = 32
default:
return nil, errors.Wrap(ErrUnsupportedAlgorithm, "invalid ECDH-ES k... | go | func (kw EcdhesKeyWrapDecrypt) KeyDecrypt(enckey []byte) ([]byte, error) {
var keysize uint32
switch kw.algorithm {
case jwa.ECDH_ES_A128KW:
keysize = 16
case jwa.ECDH_ES_A192KW:
keysize = 24
case jwa.ECDH_ES_A256KW:
keysize = 32
default:
return nil, errors.Wrap(ErrUnsupportedAlgorithm, "invalid ECDH-ES k... | [
"func",
"(",
"kw",
"EcdhesKeyWrapDecrypt",
")",
"KeyDecrypt",
"(",
"enckey",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"keysize",
"uint32",
"\n",
"switch",
"kw",
".",
"algorithm",
"{",
"case",
"jwa",
".",
"ECDH_ES_A12... | // KeyDecrypt decrypts the encrypted key using ECDH-ES | [
"KeyDecrypt",
"decrypts",
"the",
"encrypted",
"key",
"using",
"ECDH",
"-",
"ES"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/key_encrypt.go#L135-L165 |
21,280 | lestrrat-go/jwx | jwe/key_encrypt.go | NewRSAOAEPKeyEncrypt | func NewRSAOAEPKeyEncrypt(alg jwa.KeyEncryptionAlgorithm, pubkey *rsa.PublicKey) (*RSAOAEPKeyEncrypt, error) {
switch alg {
case jwa.RSA_OAEP, jwa.RSA_OAEP_256:
default:
return nil, errors.Wrap(ErrUnsupportedAlgorithm, "invalid RSA OAEP encrypt algorithm")
}
return &RSAOAEPKeyEncrypt{
alg: alg,
pubkey: pu... | go | func NewRSAOAEPKeyEncrypt(alg jwa.KeyEncryptionAlgorithm, pubkey *rsa.PublicKey) (*RSAOAEPKeyEncrypt, error) {
switch alg {
case jwa.RSA_OAEP, jwa.RSA_OAEP_256:
default:
return nil, errors.Wrap(ErrUnsupportedAlgorithm, "invalid RSA OAEP encrypt algorithm")
}
return &RSAOAEPKeyEncrypt{
alg: alg,
pubkey: pu... | [
"func",
"NewRSAOAEPKeyEncrypt",
"(",
"alg",
"jwa",
".",
"KeyEncryptionAlgorithm",
",",
"pubkey",
"*",
"rsa",
".",
"PublicKey",
")",
"(",
"*",
"RSAOAEPKeyEncrypt",
",",
"error",
")",
"{",
"switch",
"alg",
"{",
"case",
"jwa",
".",
"RSA_OAEP",
",",
"jwa",
"."... | // NewRSAOAEPKeyEncrypt creates a new key encrypter using RSA OAEP | [
"NewRSAOAEPKeyEncrypt",
"creates",
"a",
"new",
"key",
"encrypter",
"using",
"RSA",
"OAEP"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/key_encrypt.go#L168-L178 |
21,281 | lestrrat-go/jwx | jwe/key_encrypt.go | NewRSAPKCSKeyEncrypt | func NewRSAPKCSKeyEncrypt(alg jwa.KeyEncryptionAlgorithm, pubkey *rsa.PublicKey) (*RSAPKCSKeyEncrypt, error) {
switch alg {
case jwa.RSA1_5:
default:
return nil, errors.Wrap(ErrUnsupportedAlgorithm, "invalid RSA PKCS encrypt algorithm")
}
return &RSAPKCSKeyEncrypt{
alg: alg,
pubkey: pubkey,
}, nil
} | go | func NewRSAPKCSKeyEncrypt(alg jwa.KeyEncryptionAlgorithm, pubkey *rsa.PublicKey) (*RSAPKCSKeyEncrypt, error) {
switch alg {
case jwa.RSA1_5:
default:
return nil, errors.Wrap(ErrUnsupportedAlgorithm, "invalid RSA PKCS encrypt algorithm")
}
return &RSAPKCSKeyEncrypt{
alg: alg,
pubkey: pubkey,
}, nil
} | [
"func",
"NewRSAPKCSKeyEncrypt",
"(",
"alg",
"jwa",
".",
"KeyEncryptionAlgorithm",
",",
"pubkey",
"*",
"rsa",
".",
"PublicKey",
")",
"(",
"*",
"RSAPKCSKeyEncrypt",
",",
"error",
")",
"{",
"switch",
"alg",
"{",
"case",
"jwa",
".",
"RSA1_5",
":",
"default",
"... | // NewRSAPKCSKeyEncrypt creates a new key encrypter using PKCS1v15 | [
"NewRSAPKCSKeyEncrypt",
"creates",
"a",
"new",
"key",
"encrypter",
"using",
"PKCS1v15"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/key_encrypt.go#L181-L192 |
21,282 | lestrrat-go/jwx | jwe/key_encrypt.go | KeyEncrypt | func (e RSAPKCSKeyEncrypt) KeyEncrypt(cek []byte) (ByteSource, error) {
if e.alg != jwa.RSA1_5 {
return nil, errors.Wrap(ErrUnsupportedAlgorithm, "invalid RSA PKCS encrypt algorithm")
}
encrypted, err := rsa.EncryptPKCS1v15(rand.Reader, e.pubkey, cek)
if err != nil {
return nil, errors.Wrap(err, "failed to encr... | go | func (e RSAPKCSKeyEncrypt) KeyEncrypt(cek []byte) (ByteSource, error) {
if e.alg != jwa.RSA1_5 {
return nil, errors.Wrap(ErrUnsupportedAlgorithm, "invalid RSA PKCS encrypt algorithm")
}
encrypted, err := rsa.EncryptPKCS1v15(rand.Reader, e.pubkey, cek)
if err != nil {
return nil, errors.Wrap(err, "failed to encr... | [
"func",
"(",
"e",
"RSAPKCSKeyEncrypt",
")",
"KeyEncrypt",
"(",
"cek",
"[",
"]",
"byte",
")",
"(",
"ByteSource",
",",
"error",
")",
"{",
"if",
"e",
".",
"alg",
"!=",
"jwa",
".",
"RSA1_5",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"ErrUn... | // KeyEncrypt encrypts the content encryption key using RSA PKCS1v15 | [
"KeyEncrypt",
"encrypts",
"the",
"content",
"encryption",
"key",
"using",
"RSA",
"PKCS1v15"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/key_encrypt.go#L215-L224 |
21,283 | lestrrat-go/jwx | jwe/key_encrypt.go | KeyEncrypt | func (e RSAOAEPKeyEncrypt) KeyEncrypt(cek []byte) (ByteSource, error) {
var hash hash.Hash
switch e.alg {
case jwa.RSA_OAEP:
hash = sha1.New()
case jwa.RSA_OAEP_256:
hash = sha256.New()
default:
return nil, errors.New("failed to generate key encrypter for RSA-OAEP: RSA_OAEP/RSA_OAEP_256 required")
}
encryp... | go | func (e RSAOAEPKeyEncrypt) KeyEncrypt(cek []byte) (ByteSource, error) {
var hash hash.Hash
switch e.alg {
case jwa.RSA_OAEP:
hash = sha1.New()
case jwa.RSA_OAEP_256:
hash = sha256.New()
default:
return nil, errors.New("failed to generate key encrypter for RSA-OAEP: RSA_OAEP/RSA_OAEP_256 required")
}
encryp... | [
"func",
"(",
"e",
"RSAOAEPKeyEncrypt",
")",
"KeyEncrypt",
"(",
"cek",
"[",
"]",
"byte",
")",
"(",
"ByteSource",
",",
"error",
")",
"{",
"var",
"hash",
"hash",
".",
"Hash",
"\n",
"switch",
"e",
".",
"alg",
"{",
"case",
"jwa",
".",
"RSA_OAEP",
":",
"... | // KeyEncrypt encrypts the content encryption key using RSA OAEP | [
"KeyEncrypt",
"encrypts",
"the",
"content",
"encryption",
"key",
"using",
"RSA",
"OAEP"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/key_encrypt.go#L227-L242 |
21,284 | lestrrat-go/jwx | jwe/key_encrypt.go | NewRSAPKCS15KeyDecrypt | func NewRSAPKCS15KeyDecrypt(alg jwa.KeyEncryptionAlgorithm, privkey *rsa.PrivateKey, keysize int) *RSAPKCS15KeyDecrypt {
generator := NewRandomKeyGenerate(keysize * 2)
return &RSAPKCS15KeyDecrypt{
alg: alg,
privkey: privkey,
generator: generator,
}
} | go | func NewRSAPKCS15KeyDecrypt(alg jwa.KeyEncryptionAlgorithm, privkey *rsa.PrivateKey, keysize int) *RSAPKCS15KeyDecrypt {
generator := NewRandomKeyGenerate(keysize * 2)
return &RSAPKCS15KeyDecrypt{
alg: alg,
privkey: privkey,
generator: generator,
}
} | [
"func",
"NewRSAPKCS15KeyDecrypt",
"(",
"alg",
"jwa",
".",
"KeyEncryptionAlgorithm",
",",
"privkey",
"*",
"rsa",
".",
"PrivateKey",
",",
"keysize",
"int",
")",
"*",
"RSAPKCS15KeyDecrypt",
"{",
"generator",
":=",
"NewRandomKeyGenerate",
"(",
"keysize",
"*",
"2",
"... | // NewRSAPKCS15KeyDecrypt creates a new decrypter using RSA PKCS1v15 | [
"NewRSAPKCS15KeyDecrypt",
"creates",
"a",
"new",
"decrypter",
"using",
"RSA",
"PKCS1v15"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/key_encrypt.go#L245-L252 |
21,285 | lestrrat-go/jwx | jwe/key_encrypt.go | KeyDecrypt | func (d RSAPKCS15KeyDecrypt) KeyDecrypt(enckey []byte) ([]byte, error) {
if debug.Enabled {
debug.Printf("START PKCS.KeyDecrypt")
}
// Hey, these notes and workarounds were stolen from go-jose
defer func() {
// DecryptPKCS1v15SessionKey sometimes panics on an invalid payload
// because of an index out of boun... | go | func (d RSAPKCS15KeyDecrypt) KeyDecrypt(enckey []byte) ([]byte, error) {
if debug.Enabled {
debug.Printf("START PKCS.KeyDecrypt")
}
// Hey, these notes and workarounds were stolen from go-jose
defer func() {
// DecryptPKCS1v15SessionKey sometimes panics on an invalid payload
// because of an index out of boun... | [
"func",
"(",
"d",
"RSAPKCS15KeyDecrypt",
")",
"KeyDecrypt",
"(",
"enckey",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"debug",
".",
"Enabled",
"{",
"debug",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"/... | // KeyDecrypt decryptes the encrypted key using RSA PKCS1v1.5 | [
"KeyDecrypt",
"decryptes",
"the",
"encrypted",
"key",
"using",
"RSA",
"PKCS1v1",
".",
"5"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/key_encrypt.go#L260-L306 |
21,286 | lestrrat-go/jwx | jwe/key_encrypt.go | NewRSAOAEPKeyDecrypt | func NewRSAOAEPKeyDecrypt(alg jwa.KeyEncryptionAlgorithm, privkey *rsa.PrivateKey) (*RSAOAEPKeyDecrypt, error) {
switch alg {
case jwa.RSA_OAEP, jwa.RSA_OAEP_256:
default:
return nil, errors.Wrap(ErrUnsupportedAlgorithm, "invalid RSA OAEP decrypt algorithm")
}
return &RSAOAEPKeyDecrypt{
alg: alg,
privke... | go | func NewRSAOAEPKeyDecrypt(alg jwa.KeyEncryptionAlgorithm, privkey *rsa.PrivateKey) (*RSAOAEPKeyDecrypt, error) {
switch alg {
case jwa.RSA_OAEP, jwa.RSA_OAEP_256:
default:
return nil, errors.Wrap(ErrUnsupportedAlgorithm, "invalid RSA OAEP decrypt algorithm")
}
return &RSAOAEPKeyDecrypt{
alg: alg,
privke... | [
"func",
"NewRSAOAEPKeyDecrypt",
"(",
"alg",
"jwa",
".",
"KeyEncryptionAlgorithm",
",",
"privkey",
"*",
"rsa",
".",
"PrivateKey",
")",
"(",
"*",
"RSAOAEPKeyDecrypt",
",",
"error",
")",
"{",
"switch",
"alg",
"{",
"case",
"jwa",
".",
"RSA_OAEP",
",",
"jwa",
"... | // NewRSAOAEPKeyDecrypt creates a new key decrypter using RSA OAEP | [
"NewRSAOAEPKeyDecrypt",
"creates",
"a",
"new",
"key",
"decrypter",
"using",
"RSA",
"OAEP"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/key_encrypt.go#L309-L320 |
21,287 | lestrrat-go/jwx | jwe/key_encrypt.go | KeyDecrypt | func (d RSAOAEPKeyDecrypt) KeyDecrypt(enckey []byte) ([]byte, error) {
if debug.Enabled {
debug.Printf("START OAEP.KeyDecrypt")
}
var hash hash.Hash
switch d.alg {
case jwa.RSA_OAEP:
hash = sha1.New()
case jwa.RSA_OAEP_256:
hash = sha256.New()
default:
return nil, errors.New("failed to generate key encry... | go | func (d RSAOAEPKeyDecrypt) KeyDecrypt(enckey []byte) ([]byte, error) {
if debug.Enabled {
debug.Printf("START OAEP.KeyDecrypt")
}
var hash hash.Hash
switch d.alg {
case jwa.RSA_OAEP:
hash = sha1.New()
case jwa.RSA_OAEP_256:
hash = sha256.New()
default:
return nil, errors.New("failed to generate key encry... | [
"func",
"(",
"d",
"RSAOAEPKeyDecrypt",
")",
"KeyDecrypt",
"(",
"enckey",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"debug",
".",
"Enabled",
"{",
"debug",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var... | // KeyDecrypt decryptes the encrypted key using RSA OAEP | [
"KeyDecrypt",
"decryptes",
"the",
"encrypted",
"key",
"using",
"RSA",
"OAEP"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/key_encrypt.go#L328-L342 |
21,288 | lestrrat-go/jwx | jwe/key_encrypt.go | Decrypt | func (d DirectDecrypt) Decrypt() ([]byte, error) {
cek := make([]byte, len(d.Key))
copy(cek, d.Key)
return cek, nil
} | go | func (d DirectDecrypt) Decrypt() ([]byte, error) {
cek := make([]byte, len(d.Key))
copy(cek, d.Key)
return cek, nil
} | [
"func",
"(",
"d",
"DirectDecrypt",
")",
"Decrypt",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"cek",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"d",
".",
"Key",
")",
")",
"\n",
"copy",
"(",
"cek",
",",
"d",
".",
"Ke... | // Decrypt for DirectDecrypt does not do anything other than
// return a copy of the embedded key | [
"Decrypt",
"for",
"DirectDecrypt",
"does",
"not",
"do",
"anything",
"other",
"than",
"return",
"a",
"copy",
"of",
"the",
"embedded",
"key"
] | 0251e8147021ce27b0d3b1812b7c07265fe7a538 | https://github.com/lestrrat-go/jwx/blob/0251e8147021ce27b0d3b1812b7c07265fe7a538/jwe/key_encrypt.go#L346-L350 |
21,289 | jrallison/go-workers | hooks.go | DuringDrain | func DuringDrain(f func()) {
access.Lock()
defer access.Unlock()
duringDrain = append(duringDrain, f)
} | go | func DuringDrain(f func()) {
access.Lock()
defer access.Unlock()
duringDrain = append(duringDrain, f)
} | [
"func",
"DuringDrain",
"(",
"f",
"func",
"(",
")",
")",
"{",
"access",
".",
"Lock",
"(",
")",
"\n",
"defer",
"access",
".",
"Unlock",
"(",
")",
"\n",
"duringDrain",
"=",
"append",
"(",
"duringDrain",
",",
"f",
")",
"\n",
"}"
] | // func AfterStart
// func BeforeQuit
// func AfterQuit | [
"func",
"AfterStart",
"func",
"BeforeQuit",
"func",
"AfterQuit"
] | dbf81d0b75bbe2fd90ef66a07643dd70cb42a88a | https://github.com/jrallison/go-workers/blob/dbf81d0b75bbe2fd90ef66a07643dd70cb42a88a/hooks.go#L16-L20 |
21,290 | eapache/go-resiliency | semaphore/semaphore.go | New | func New(tickets int, timeout time.Duration) *Semaphore {
return &Semaphore{
sem: make(chan struct{}, tickets),
timeout: timeout,
}
} | go | func New(tickets int, timeout time.Duration) *Semaphore {
return &Semaphore{
sem: make(chan struct{}, tickets),
timeout: timeout,
}
} | [
"func",
"New",
"(",
"tickets",
"int",
",",
"timeout",
"time",
".",
"Duration",
")",
"*",
"Semaphore",
"{",
"return",
"&",
"Semaphore",
"{",
"sem",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
",",
"tickets",
")",
",",
"timeout",
":",
"timeout",
",",... | // New constructs a new Semaphore with the given ticket-count
// and timeout. | [
"New",
"constructs",
"a",
"new",
"Semaphore",
"with",
"the",
"given",
"ticket",
"-",
"count",
"and",
"timeout",
"."
] | 842e16ec2c98ef0c59eebfe60d2d3500a793ba19 | https://github.com/eapache/go-resiliency/blob/842e16ec2c98ef0c59eebfe60d2d3500a793ba19/semaphore/semaphore.go#L21-L26 |
21,291 | eapache/go-resiliency | semaphore/semaphore.go | Acquire | func (s *Semaphore) Acquire() error {
select {
case s.sem <- struct{}{}:
return nil
case <-time.After(s.timeout):
return ErrNoTickets
}
} | go | func (s *Semaphore) Acquire() error {
select {
case s.sem <- struct{}{}:
return nil
case <-time.After(s.timeout):
return ErrNoTickets
}
} | [
"func",
"(",
"s",
"*",
"Semaphore",
")",
"Acquire",
"(",
")",
"error",
"{",
"select",
"{",
"case",
"s",
".",
"sem",
"<-",
"struct",
"{",
"}",
"{",
"}",
":",
"return",
"nil",
"\n",
"case",
"<-",
"time",
".",
"After",
"(",
"s",
".",
"timeout",
")... | // Acquire tries to acquire a ticket from the semaphore. If it can, it returns nil.
// If it cannot after "timeout" amount of time, it returns ErrNoTickets. It is
// safe to call Acquire concurrently on a single Semaphore. | [
"Acquire",
"tries",
"to",
"acquire",
"a",
"ticket",
"from",
"the",
"semaphore",
".",
"If",
"it",
"can",
"it",
"returns",
"nil",
".",
"If",
"it",
"cannot",
"after",
"timeout",
"amount",
"of",
"time",
"it",
"returns",
"ErrNoTickets",
".",
"It",
"is",
"safe... | 842e16ec2c98ef0c59eebfe60d2d3500a793ba19 | https://github.com/eapache/go-resiliency/blob/842e16ec2c98ef0c59eebfe60d2d3500a793ba19/semaphore/semaphore.go#L31-L38 |
21,292 | eapache/go-resiliency | breaker/breaker.go | New | func New(errorThreshold, successThreshold int, timeout time.Duration) *Breaker {
return &Breaker{
errorThreshold: errorThreshold,
successThreshold: successThreshold,
timeout: timeout,
}
} | go | func New(errorThreshold, successThreshold int, timeout time.Duration) *Breaker {
return &Breaker{
errorThreshold: errorThreshold,
successThreshold: successThreshold,
timeout: timeout,
}
} | [
"func",
"New",
"(",
"errorThreshold",
",",
"successThreshold",
"int",
",",
"timeout",
"time",
".",
"Duration",
")",
"*",
"Breaker",
"{",
"return",
"&",
"Breaker",
"{",
"errorThreshold",
":",
"errorThreshold",
",",
"successThreshold",
":",
"successThreshold",
","... | // New constructs a new circuit-breaker that starts closed.
// From closed, the breaker opens if "errorThreshold" errors are seen
// without an error-free period of at least "timeout". From open, the
// breaker half-closes after "timeout". From half-open, the breaker closes
// after "successThreshold" consecutive succe... | [
"New",
"constructs",
"a",
"new",
"circuit",
"-",
"breaker",
"that",
"starts",
"closed",
".",
"From",
"closed",
"the",
"breaker",
"opens",
"if",
"errorThreshold",
"errors",
"are",
"seen",
"without",
"an",
"error",
"-",
"free",
"period",
"of",
"at",
"least",
... | 842e16ec2c98ef0c59eebfe60d2d3500a793ba19 | https://github.com/eapache/go-resiliency/blob/842e16ec2c98ef0c59eebfe60d2d3500a793ba19/breaker/breaker.go#L37-L43 |
21,293 | eapache/go-resiliency | breaker/breaker.go | Run | func (b *Breaker) Run(work func() error) error {
state := atomic.LoadUint32(&b.state)
if state == open {
return ErrBreakerOpen
}
return b.doWork(state, work)
} | go | func (b *Breaker) Run(work func() error) error {
state := atomic.LoadUint32(&b.state)
if state == open {
return ErrBreakerOpen
}
return b.doWork(state, work)
} | [
"func",
"(",
"b",
"*",
"Breaker",
")",
"Run",
"(",
"work",
"func",
"(",
")",
"error",
")",
"error",
"{",
"state",
":=",
"atomic",
".",
"LoadUint32",
"(",
"&",
"b",
".",
"state",
")",
"\n\n",
"if",
"state",
"==",
"open",
"{",
"return",
"ErrBreakerOp... | // Run will either return ErrBreakerOpen immediately if the circuit-breaker is
// already open, or it will run the given function and pass along its return
// value. It is safe to call Run concurrently on the same Breaker. | [
"Run",
"will",
"either",
"return",
"ErrBreakerOpen",
"immediately",
"if",
"the",
"circuit",
"-",
"breaker",
"is",
"already",
"open",
"or",
"it",
"will",
"run",
"the",
"given",
"function",
"and",
"pass",
"along",
"its",
"return",
"value",
".",
"It",
"is",
"... | 842e16ec2c98ef0c59eebfe60d2d3500a793ba19 | https://github.com/eapache/go-resiliency/blob/842e16ec2c98ef0c59eebfe60d2d3500a793ba19/breaker/breaker.go#L48-L56 |
21,294 | eapache/go-resiliency | retrier/backoffs.go | ConstantBackoff | func ConstantBackoff(n int, amount time.Duration) []time.Duration {
ret := make([]time.Duration, n)
for i := range ret {
ret[i] = amount
}
return ret
} | go | func ConstantBackoff(n int, amount time.Duration) []time.Duration {
ret := make([]time.Duration, n)
for i := range ret {
ret[i] = amount
}
return ret
} | [
"func",
"ConstantBackoff",
"(",
"n",
"int",
",",
"amount",
"time",
".",
"Duration",
")",
"[",
"]",
"time",
".",
"Duration",
"{",
"ret",
":=",
"make",
"(",
"[",
"]",
"time",
".",
"Duration",
",",
"n",
")",
"\n",
"for",
"i",
":=",
"range",
"ret",
"... | // ConstantBackoff generates a simple back-off strategy of retrying 'n' times, and waiting 'amount' time after each one. | [
"ConstantBackoff",
"generates",
"a",
"simple",
"back",
"-",
"off",
"strategy",
"of",
"retrying",
"n",
"times",
"and",
"waiting",
"amount",
"time",
"after",
"each",
"one",
"."
] | 842e16ec2c98ef0c59eebfe60d2d3500a793ba19 | https://github.com/eapache/go-resiliency/blob/842e16ec2c98ef0c59eebfe60d2d3500a793ba19/retrier/backoffs.go#L6-L12 |
21,295 | eapache/go-resiliency | retrier/backoffs.go | ExponentialBackoff | func ExponentialBackoff(n int, initialAmount time.Duration) []time.Duration {
ret := make([]time.Duration, n)
next := initialAmount
for i := range ret {
ret[i] = next
next *= 2
}
return ret
} | go | func ExponentialBackoff(n int, initialAmount time.Duration) []time.Duration {
ret := make([]time.Duration, n)
next := initialAmount
for i := range ret {
ret[i] = next
next *= 2
}
return ret
} | [
"func",
"ExponentialBackoff",
"(",
"n",
"int",
",",
"initialAmount",
"time",
".",
"Duration",
")",
"[",
"]",
"time",
".",
"Duration",
"{",
"ret",
":=",
"make",
"(",
"[",
"]",
"time",
".",
"Duration",
",",
"n",
")",
"\n",
"next",
":=",
"initialAmount",
... | // ExponentialBackoff generates a simple back-off strategy of retrying 'n' times, and doubling the amount of
// time waited after each one. | [
"ExponentialBackoff",
"generates",
"a",
"simple",
"back",
"-",
"off",
"strategy",
"of",
"retrying",
"n",
"times",
"and",
"doubling",
"the",
"amount",
"of",
"time",
"waited",
"after",
"each",
"one",
"."
] | 842e16ec2c98ef0c59eebfe60d2d3500a793ba19 | https://github.com/eapache/go-resiliency/blob/842e16ec2c98ef0c59eebfe60d2d3500a793ba19/retrier/backoffs.go#L16-L24 |
21,296 | eapache/go-resiliency | retrier/retrier.go | New | func New(backoff []time.Duration, class Classifier) *Retrier {
if class == nil {
class = DefaultClassifier{}
}
return &Retrier{
backoff: backoff,
class: class,
rand: rand.New(rand.NewSource(time.Now().UnixNano())),
}
} | go | func New(backoff []time.Duration, class Classifier) *Retrier {
if class == nil {
class = DefaultClassifier{}
}
return &Retrier{
backoff: backoff,
class: class,
rand: rand.New(rand.NewSource(time.Now().UnixNano())),
}
} | [
"func",
"New",
"(",
"backoff",
"[",
"]",
"time",
".",
"Duration",
",",
"class",
"Classifier",
")",
"*",
"Retrier",
"{",
"if",
"class",
"==",
"nil",
"{",
"class",
"=",
"DefaultClassifier",
"{",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"Retrier",
"{",
"b... | // New constructs a Retrier with the given backoff pattern and classifier. The length of the backoff pattern
// indicates how many times an action will be retried, and the value at each index indicates the amount of time
// waited before each subsequent retry. The classifier is used to determine which errors should be ... | [
"New",
"constructs",
"a",
"Retrier",
"with",
"the",
"given",
"backoff",
"pattern",
"and",
"classifier",
".",
"The",
"length",
"of",
"the",
"backoff",
"pattern",
"indicates",
"how",
"many",
"times",
"an",
"action",
"will",
"be",
"retried",
"and",
"the",
"valu... | 842e16ec2c98ef0c59eebfe60d2d3500a793ba19 | https://github.com/eapache/go-resiliency/blob/842e16ec2c98ef0c59eebfe60d2d3500a793ba19/retrier/retrier.go#L25-L35 |
21,297 | eapache/go-resiliency | retrier/retrier.go | Run | func (r *Retrier) Run(work func() error) error {
return r.RunCtx(context.Background(), func(ctx context.Context) error {
// never use ctx
return work()
})
} | go | func (r *Retrier) Run(work func() error) error {
return r.RunCtx(context.Background(), func(ctx context.Context) error {
// never use ctx
return work()
})
} | [
"func",
"(",
"r",
"*",
"Retrier",
")",
"Run",
"(",
"work",
"func",
"(",
")",
"error",
")",
"error",
"{",
"return",
"r",
".",
"RunCtx",
"(",
"context",
".",
"Background",
"(",
")",
",",
"func",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
... | // Run executes the given work function by executing RunCtx without context.Context. | [
"Run",
"executes",
"the",
"given",
"work",
"function",
"by",
"executing",
"RunCtx",
"without",
"context",
".",
"Context",
"."
] | 842e16ec2c98ef0c59eebfe60d2d3500a793ba19 | https://github.com/eapache/go-resiliency/blob/842e16ec2c98ef0c59eebfe60d2d3500a793ba19/retrier/retrier.go#L38-L43 |
21,298 | eapache/go-resiliency | retrier/retrier.go | RunCtx | func (r *Retrier) RunCtx(ctx context.Context, work func(ctx context.Context) error) error {
retries := 0
for {
ret := work(ctx)
switch r.class.Classify(ret) {
case Succeed, Fail:
return ret
case Retry:
if retries >= len(r.backoff) {
return ret
}
timeout := time.After(r.calcSleep(retries))
... | go | func (r *Retrier) RunCtx(ctx context.Context, work func(ctx context.Context) error) error {
retries := 0
for {
ret := work(ctx)
switch r.class.Classify(ret) {
case Succeed, Fail:
return ret
case Retry:
if retries >= len(r.backoff) {
return ret
}
timeout := time.After(r.calcSleep(retries))
... | [
"func",
"(",
"r",
"*",
"Retrier",
")",
"RunCtx",
"(",
"ctx",
"context",
".",
"Context",
",",
"work",
"func",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
")",
"error",
"{",
"retries",
":=",
"0",
"\n",
"for",
"{",
"ret",
":=",
"work",
"(",
... | // RunCtx executes the given work function, then classifies its return value based on the classifier used
// to construct the Retrier. If the result is Succeed or Fail, the return value of the work function is
// returned to the caller. If the result is Retry, then Run sleeps according to the its backoff policy
// befo... | [
"RunCtx",
"executes",
"the",
"given",
"work",
"function",
"then",
"classifies",
"its",
"return",
"value",
"based",
"on",
"the",
"classifier",
"used",
"to",
"construct",
"the",
"Retrier",
".",
"If",
"the",
"result",
"is",
"Succeed",
"or",
"Fail",
"the",
"retu... | 842e16ec2c98ef0c59eebfe60d2d3500a793ba19 | https://github.com/eapache/go-resiliency/blob/842e16ec2c98ef0c59eebfe60d2d3500a793ba19/retrier/retrier.go#L50-L71 |
21,299 | eapache/go-resiliency | batcher/batcher.go | New | func New(timeout time.Duration, doWork func([]interface{}) error) *Batcher {
return &Batcher{
timeout: timeout,
doWork: doWork,
}
} | go | func New(timeout time.Duration, doWork func([]interface{}) error) *Batcher {
return &Batcher{
timeout: timeout,
doWork: doWork,
}
} | [
"func",
"New",
"(",
"timeout",
"time",
".",
"Duration",
",",
"doWork",
"func",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
"error",
")",
"*",
"Batcher",
"{",
"return",
"&",
"Batcher",
"{",
"timeout",
":",
"timeout",
",",
"doWork",
":",
"doWork",
",",
... | // New constructs a new batcher that will batch all calls to Run that occur within
// `timeout` time before calling doWork just once for the entire batch. The doWork
// function must be safe to run concurrently with itself as this may occur, especially
// when the timeout is small. | [
"New",
"constructs",
"a",
"new",
"batcher",
"that",
"will",
"batch",
"all",
"calls",
"to",
"Run",
"that",
"occur",
"within",
"timeout",
"time",
"before",
"calling",
"doWork",
"just",
"once",
"for",
"the",
"entire",
"batch",
".",
"The",
"doWork",
"function",
... | 842e16ec2c98ef0c59eebfe60d2d3500a793ba19 | https://github.com/eapache/go-resiliency/blob/842e16ec2c98ef0c59eebfe60d2d3500a793ba19/batcher/batcher.go#L28-L33 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.