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
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
1,400 | keybase/saltpack | armor62_encrypt.go | NewEncryptArmor62Stream | func NewEncryptArmor62Stream(version Version, ciphertext io.Writer, sender BoxSecretKey, receivers []BoxPublicKey, brand string) (plaintext io.WriteCloser, err error) {
ephemeralKeyCreator, err := receiversToEphemeralKeyCreator(receivers)
if err != nil {
return nil, err
}
return newEncryptArmor62Stream(version, ciphertext, sender, receivers, ephemeralKeyCreator, defaultEncryptRNG{}, brand)
} | go | func NewEncryptArmor62Stream(version Version, ciphertext io.Writer, sender BoxSecretKey, receivers []BoxPublicKey, brand string) (plaintext io.WriteCloser, err error) {
ephemeralKeyCreator, err := receiversToEphemeralKeyCreator(receivers)
if err != nil {
return nil, err
}
return newEncryptArmor62Stream(version, ciphertext, sender, receivers, ephemeralKeyCreator, defaultEncryptRNG{}, brand)
} | [
"func",
"NewEncryptArmor62Stream",
"(",
"version",
"Version",
",",
"ciphertext",
"io",
".",
"Writer",
",",
"sender",
"BoxSecretKey",
",",
"receivers",
"[",
"]",
"BoxPublicKey",
",",
"brand",
"string",
")",
"(",
"plaintext",
"io",
".",
"WriteCloser",
",",
"err",
"error",
")",
"{",
"ephemeralKeyCreator",
",",
"err",
":=",
"receiversToEphemeralKeyCreator",
"(",
"receivers",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newEncryptArmor62Stream",
"(",
"version",
",",
"ciphertext",
",",
"sender",
",",
"receivers",
",",
"ephemeralKeyCreator",
",",
"defaultEncryptRNG",
"{",
"}",
",",
"brand",
")",
"\n",
"}"
] | // NewEncryptArmor62Stream creates a stream that consumes plaintext data.
// It will write out encrypted data to the io.Writer passed in as ciphertext.
// The encryption is from the specified sender, and is encrypted for the
// given receivers.
//
// The "brand" is the optional "brand" string to put into the header
// and footer.
//
// The ciphertext is additionally armored with the recommended armor62-style format.
//
// If initialization succeeds, returns an io.WriteCloser that accepts
// plaintext data to be encrypted and a nil error. Otherwise, returns
// nil and the initialization error. | [
"NewEncryptArmor62Stream",
"creates",
"a",
"stream",
"that",
"consumes",
"plaintext",
"data",
".",
"It",
"will",
"write",
"out",
"encrypted",
"data",
"to",
"the",
"io",
".",
"Writer",
"passed",
"in",
"as",
"ciphertext",
".",
"The",
"encryption",
"is",
"from",
"the",
"specified",
"sender",
"and",
"is",
"encrypted",
"for",
"the",
"given",
"receivers",
".",
"The",
"brand",
"is",
"the",
"optional",
"brand",
"string",
"to",
"put",
"into",
"the",
"header",
"and",
"footer",
".",
"The",
"ciphertext",
"is",
"additionally",
"armored",
"with",
"the",
"recommended",
"armor62",
"-",
"style",
"format",
".",
"If",
"initialization",
"succeeds",
"returns",
"an",
"io",
".",
"WriteCloser",
"that",
"accepts",
"plaintext",
"data",
"to",
"be",
"encrypted",
"and",
"a",
"nil",
"error",
".",
"Otherwise",
"returns",
"nil",
"and",
"the",
"initialization",
"error",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/armor62_encrypt.go#L51-L57 |
1,401 | keybase/saltpack | encoding/basex/stream.go | Close | func (e *encoder) Close() error {
// If there's anything left in the buffer, flush it out
if e.err == nil && e.nbuf > 0 {
e.enc.Encode(e.out[:], e.buf[:e.nbuf])
_, e.err = e.w.Write(e.out[:e.enc.EncodedLen(e.nbuf)])
e.nbuf = 0
}
return e.err
} | go | func (e *encoder) Close() error {
// If there's anything left in the buffer, flush it out
if e.err == nil && e.nbuf > 0 {
e.enc.Encode(e.out[:], e.buf[:e.nbuf])
_, e.err = e.w.Write(e.out[:e.enc.EncodedLen(e.nbuf)])
e.nbuf = 0
}
return e.err
} | [
"func",
"(",
"e",
"*",
"encoder",
")",
"Close",
"(",
")",
"error",
"{",
"// If there's anything left in the buffer, flush it out",
"if",
"e",
".",
"err",
"==",
"nil",
"&&",
"e",
".",
"nbuf",
">",
"0",
"{",
"e",
".",
"enc",
".",
"Encode",
"(",
"e",
".",
"out",
"[",
":",
"]",
",",
"e",
".",
"buf",
"[",
":",
"e",
".",
"nbuf",
"]",
")",
"\n",
"_",
",",
"e",
".",
"err",
"=",
"e",
".",
"w",
".",
"Write",
"(",
"e",
".",
"out",
"[",
":",
"e",
".",
"enc",
".",
"EncodedLen",
"(",
"e",
".",
"nbuf",
")",
"]",
")",
"\n",
"e",
".",
"nbuf",
"=",
"0",
"\n",
"}",
"\n",
"return",
"e",
".",
"err",
"\n",
"}"
] | // Close flushes any pending output from the encoder.
// It is an error to call Write after calling Close. | [
"Close",
"flushes",
"any",
"pending",
"output",
"from",
"the",
"encoder",
".",
"It",
"is",
"an",
"error",
"to",
"call",
"Write",
"after",
"calling",
"Close",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/encoding/basex/stream.go#L77-L85 |
1,402 | keybase/saltpack | encoding/basex/stream.go | NewEncoder | func NewEncoder(enc *Encoding, w io.Writer) io.WriteCloser {
return &encoder{
enc: enc,
w: w,
buf: make([]byte, enc.base256BlockLen),
out: make([]byte, 128*enc.baseXBlockLen),
}
} | go | func NewEncoder(enc *Encoding, w io.Writer) io.WriteCloser {
return &encoder{
enc: enc,
w: w,
buf: make([]byte, enc.base256BlockLen),
out: make([]byte, 128*enc.baseXBlockLen),
}
} | [
"func",
"NewEncoder",
"(",
"enc",
"*",
"Encoding",
",",
"w",
"io",
".",
"Writer",
")",
"io",
".",
"WriteCloser",
"{",
"return",
"&",
"encoder",
"{",
"enc",
":",
"enc",
",",
"w",
":",
"w",
",",
"buf",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"enc",
".",
"base256BlockLen",
")",
",",
"out",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"128",
"*",
"enc",
".",
"baseXBlockLen",
")",
",",
"}",
"\n",
"}"
] | // NewEncoder returns a new baseX stream encoder. Data written to
// the returned writer will be encoded using enc and then written to w.
// Encodings operate in enc.baseXBlockLen-byte blocks; when finished
// writing, the caller must Close the returned encoder to flush any
// partially written blocks. | [
"NewEncoder",
"returns",
"a",
"new",
"baseX",
"stream",
"encoder",
".",
"Data",
"written",
"to",
"the",
"returned",
"writer",
"will",
"be",
"encoded",
"using",
"enc",
"and",
"then",
"written",
"to",
"w",
".",
"Encodings",
"operate",
"in",
"enc",
".",
"baseXBlockLen",
"-",
"byte",
"blocks",
";",
"when",
"finished",
"writing",
"the",
"caller",
"must",
"Close",
"the",
"returned",
"encoder",
"to",
"flush",
"any",
"partially",
"written",
"blocks",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/encoding/basex/stream.go#L92-L99 |
1,403 | keybase/saltpack | encoding/basex/stream.go | NewDecoder | func NewDecoder(enc *Encoding, r io.Reader) io.Reader {
return newDecoder(enc, r)
} | go | func NewDecoder(enc *Encoding, r io.Reader) io.Reader {
return newDecoder(enc, r)
} | [
"func",
"NewDecoder",
"(",
"enc",
"*",
"Encoding",
",",
"r",
"io",
".",
"Reader",
")",
"io",
".",
"Reader",
"{",
"return",
"newDecoder",
"(",
"enc",
",",
"r",
")",
"\n",
"}"
] | // NewDecoder constructs a new baseX stream decoder. | [
"NewDecoder",
"constructs",
"a",
"new",
"baseX",
"stream",
"decoder",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/encoding/basex/stream.go#L234-L236 |
1,404 | keybase/saltpack | signcrypt_open.go | NewSigncryptOpenStream | func NewSigncryptOpenStream(r io.Reader, keyring SigncryptKeyring, resolver SymmetricKeyResolver) (senderPub SigningPublicKey, plaintext io.Reader, err error) {
sos := &signcryptOpenStream{
mps: newMsgpackStream(r),
keyring: keyring,
resolver: resolver,
}
err = sos.readHeader()
if err != nil {
return nil, nil, err
}
return sos.signingPublicKey, newChunkReader(sos), nil
} | go | func NewSigncryptOpenStream(r io.Reader, keyring SigncryptKeyring, resolver SymmetricKeyResolver) (senderPub SigningPublicKey, plaintext io.Reader, err error) {
sos := &signcryptOpenStream{
mps: newMsgpackStream(r),
keyring: keyring,
resolver: resolver,
}
err = sos.readHeader()
if err != nil {
return nil, nil, err
}
return sos.signingPublicKey, newChunkReader(sos), nil
} | [
"func",
"NewSigncryptOpenStream",
"(",
"r",
"io",
".",
"Reader",
",",
"keyring",
"SigncryptKeyring",
",",
"resolver",
"SymmetricKeyResolver",
")",
"(",
"senderPub",
"SigningPublicKey",
",",
"plaintext",
"io",
".",
"Reader",
",",
"err",
"error",
")",
"{",
"sos",
":=",
"&",
"signcryptOpenStream",
"{",
"mps",
":",
"newMsgpackStream",
"(",
"r",
")",
",",
"keyring",
":",
"keyring",
",",
"resolver",
":",
"resolver",
",",
"}",
"\n\n",
"err",
"=",
"sos",
".",
"readHeader",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"sos",
".",
"signingPublicKey",
",",
"newChunkReader",
"(",
"sos",
")",
",",
"nil",
"\n",
"}"
] | // NewSigncryptOpenStream starts a streaming verification and decryption. It
// synchronously ingests and parses the given Reader's encryption header. It
// consults the passed keyring for the decryption keys needed to decrypt the
// message. On failure, it returns a null Reader and an error message. On
// success, it returns a Reader with the plaintext stream, and a nil error. In
// either case, it will return a `MessageKeyInfo` which tells about who the
// sender was, and which of the Receiver's keys was used to decrypt the
// message.
//
// Note that the caller has an opportunity not to ingest the plaintext if he
// doesn't trust the sender revealed in the MessageKeyInfo.
// | [
"NewSigncryptOpenStream",
"starts",
"a",
"streaming",
"verification",
"and",
"decryption",
".",
"It",
"synchronously",
"ingests",
"and",
"parses",
"the",
"given",
"Reader",
"s",
"encryption",
"header",
".",
"It",
"consults",
"the",
"passed",
"keyring",
"for",
"the",
"decryption",
"keys",
"needed",
"to",
"decrypt",
"the",
"message",
".",
"On",
"failure",
"it",
"returns",
"a",
"null",
"Reader",
"and",
"an",
"error",
"message",
".",
"On",
"success",
"it",
"returns",
"a",
"Reader",
"with",
"the",
"plaintext",
"stream",
"and",
"a",
"nil",
"error",
".",
"In",
"either",
"case",
"it",
"will",
"return",
"a",
"MessageKeyInfo",
"which",
"tells",
"about",
"who",
"the",
"sender",
"was",
"and",
"which",
"of",
"the",
"Receiver",
"s",
"keys",
"was",
"used",
"to",
"decrypt",
"the",
"message",
".",
"Note",
"that",
"the",
"caller",
"has",
"an",
"opportunity",
"not",
"to",
"ingest",
"the",
"plaintext",
"if",
"he",
"doesn",
"t",
"trust",
"the",
"sender",
"revealed",
"in",
"the",
"MessageKeyInfo",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/signcrypt_open.go#L237-L250 |
1,405 | keybase/saltpack | signcrypt_open.go | SigncryptOpen | func SigncryptOpen(ciphertext []byte, keyring SigncryptKeyring, resolver SymmetricKeyResolver) (senderPub SigningPublicKey, plaintext []byte, err error) {
buf := bytes.NewBuffer(ciphertext)
senderPub, plaintextStream, err := NewSigncryptOpenStream(buf, keyring, resolver)
if err != nil {
return senderPub, nil, err
}
ret, err := ioutil.ReadAll(plaintextStream)
if err != nil {
return nil, nil, err
}
return senderPub, ret, err
} | go | func SigncryptOpen(ciphertext []byte, keyring SigncryptKeyring, resolver SymmetricKeyResolver) (senderPub SigningPublicKey, plaintext []byte, err error) {
buf := bytes.NewBuffer(ciphertext)
senderPub, plaintextStream, err := NewSigncryptOpenStream(buf, keyring, resolver)
if err != nil {
return senderPub, nil, err
}
ret, err := ioutil.ReadAll(plaintextStream)
if err != nil {
return nil, nil, err
}
return senderPub, ret, err
} | [
"func",
"SigncryptOpen",
"(",
"ciphertext",
"[",
"]",
"byte",
",",
"keyring",
"SigncryptKeyring",
",",
"resolver",
"SymmetricKeyResolver",
")",
"(",
"senderPub",
"SigningPublicKey",
",",
"plaintext",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"ciphertext",
")",
"\n",
"senderPub",
",",
"plaintextStream",
",",
"err",
":=",
"NewSigncryptOpenStream",
"(",
"buf",
",",
"keyring",
",",
"resolver",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"senderPub",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"ret",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"plaintextStream",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"senderPub",
",",
"ret",
",",
"err",
"\n",
"}"
] | // SigncryptOpen simply opens a ciphertext given the set of keys in the specified keyring.
// It returns a plaintext on sucess, and an error on failure. It returns the header's
// MessageKeyInfo in either case. | [
"SigncryptOpen",
"simply",
"opens",
"a",
"ciphertext",
"given",
"the",
"set",
"of",
"keys",
"in",
"the",
"specified",
"keyring",
".",
"It",
"returns",
"a",
"plaintext",
"on",
"sucess",
"and",
"an",
"error",
"on",
"failure",
".",
"It",
"returns",
"the",
"header",
"s",
"MessageKeyInfo",
"in",
"either",
"case",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/signcrypt_open.go#L260-L271 |
1,406 | keybase/saltpack | armor62_signcrypt.go | NewSigncryptArmor62SealStream | func NewSigncryptArmor62SealStream(ciphertext io.Writer, ephemeralKeyCreator EphemeralKeyCreator, sender SigningSecretKey, receiverBoxKeys []BoxPublicKey, receiverSymmetricKeys []ReceiverSymmetricKey, brand string) (plaintext io.WriteCloser, err error) {
return newSigncryptArmor62SealStream(ciphertext, sender, receiverBoxKeys, receiverSymmetricKeys, ephemeralKeyCreator, defaultSigncryptRNG{}, brand)
} | go | func NewSigncryptArmor62SealStream(ciphertext io.Writer, ephemeralKeyCreator EphemeralKeyCreator, sender SigningSecretKey, receiverBoxKeys []BoxPublicKey, receiverSymmetricKeys []ReceiverSymmetricKey, brand string) (plaintext io.WriteCloser, err error) {
return newSigncryptArmor62SealStream(ciphertext, sender, receiverBoxKeys, receiverSymmetricKeys, ephemeralKeyCreator, defaultSigncryptRNG{}, brand)
} | [
"func",
"NewSigncryptArmor62SealStream",
"(",
"ciphertext",
"io",
".",
"Writer",
",",
"ephemeralKeyCreator",
"EphemeralKeyCreator",
",",
"sender",
"SigningSecretKey",
",",
"receiverBoxKeys",
"[",
"]",
"BoxPublicKey",
",",
"receiverSymmetricKeys",
"[",
"]",
"ReceiverSymmetricKey",
",",
"brand",
"string",
")",
"(",
"plaintext",
"io",
".",
"WriteCloser",
",",
"err",
"error",
")",
"{",
"return",
"newSigncryptArmor62SealStream",
"(",
"ciphertext",
",",
"sender",
",",
"receiverBoxKeys",
",",
"receiverSymmetricKeys",
",",
"ephemeralKeyCreator",
",",
"defaultSigncryptRNG",
"{",
"}",
",",
"brand",
")",
"\n",
"}"
] | // NewSigncryptArmor62SealStream creates a stream that consumes plaintext data.
// It will write out signcrypted data to the io.Writer passed in as ciphertext.
// The signcryption is from the specified sender, and is signcrypted for the
// given receivers.
//
// The "brand" is the optional "brand" string to put into the header
// and footer.
//
// The ciphertext is additionally armored with the recommended armor62-style format.
//
// If initialization succeeds, returns an io.WriteCloser that accepts
// plaintext data to be signcrypted and a nil error. Otherwise,
// returns nil and the initialization error.
//
// ephemeralKeyCreator should be the last argument; it's the 2nd one
// to preserve the public API. | [
"NewSigncryptArmor62SealStream",
"creates",
"a",
"stream",
"that",
"consumes",
"plaintext",
"data",
".",
"It",
"will",
"write",
"out",
"signcrypted",
"data",
"to",
"the",
"io",
".",
"Writer",
"passed",
"in",
"as",
"ciphertext",
".",
"The",
"signcryption",
"is",
"from",
"the",
"specified",
"sender",
"and",
"is",
"signcrypted",
"for",
"the",
"given",
"receivers",
".",
"The",
"brand",
"is",
"the",
"optional",
"brand",
"string",
"to",
"put",
"into",
"the",
"header",
"and",
"footer",
".",
"The",
"ciphertext",
"is",
"additionally",
"armored",
"with",
"the",
"recommended",
"armor62",
"-",
"style",
"format",
".",
"If",
"initialization",
"succeeds",
"returns",
"an",
"io",
".",
"WriteCloser",
"that",
"accepts",
"plaintext",
"data",
"to",
"be",
"signcrypted",
"and",
"a",
"nil",
"error",
".",
"Otherwise",
"returns",
"nil",
"and",
"the",
"initialization",
"error",
".",
"ephemeralKeyCreator",
"should",
"be",
"the",
"last",
"argument",
";",
"it",
"s",
"the",
"2nd",
"one",
"to",
"preserve",
"the",
"public",
"API",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/armor62_signcrypt.go#L47-L49 |
1,407 | keybase/saltpack | armor62_signcrypt.go | NewDearmor62SigncryptOpenStream | func NewDearmor62SigncryptOpenStream(ciphertext io.Reader, keyring SigncryptKeyring, resolver SymmetricKeyResolver) (SigningPublicKey, io.Reader, string, error) {
dearmored, frame, err := NewArmor62DecoderStream(ciphertext, armor62SigncryptionHeaderChecker, armor62SigncryptionFrameChecker)
if err != nil {
return nil, nil, "", err
}
brand, err := frame.GetBrand()
if err != nil {
return nil, nil, "", err
}
mki, r, err := NewSigncryptOpenStream(dearmored, keyring, resolver)
if err != nil {
return mki, nil, "", err
}
return mki, r, brand, nil
} | go | func NewDearmor62SigncryptOpenStream(ciphertext io.Reader, keyring SigncryptKeyring, resolver SymmetricKeyResolver) (SigningPublicKey, io.Reader, string, error) {
dearmored, frame, err := NewArmor62DecoderStream(ciphertext, armor62SigncryptionHeaderChecker, armor62SigncryptionFrameChecker)
if err != nil {
return nil, nil, "", err
}
brand, err := frame.GetBrand()
if err != nil {
return nil, nil, "", err
}
mki, r, err := NewSigncryptOpenStream(dearmored, keyring, resolver)
if err != nil {
return mki, nil, "", err
}
return mki, r, brand, nil
} | [
"func",
"NewDearmor62SigncryptOpenStream",
"(",
"ciphertext",
"io",
".",
"Reader",
",",
"keyring",
"SigncryptKeyring",
",",
"resolver",
"SymmetricKeyResolver",
")",
"(",
"SigningPublicKey",
",",
"io",
".",
"Reader",
",",
"string",
",",
"error",
")",
"{",
"dearmored",
",",
"frame",
",",
"err",
":=",
"NewArmor62DecoderStream",
"(",
"ciphertext",
",",
"armor62SigncryptionHeaderChecker",
",",
"armor62SigncryptionFrameChecker",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"brand",
",",
"err",
":=",
"frame",
".",
"GetBrand",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"mki",
",",
"r",
",",
"err",
":=",
"NewSigncryptOpenStream",
"(",
"dearmored",
",",
"keyring",
",",
"resolver",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"mki",
",",
"nil",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"mki",
",",
"r",
",",
"brand",
",",
"nil",
"\n",
"}"
] | // NewDearmor62SigncryptOpenStream makes a new stream that dearmors and decrypts the given
// Reader stream. Pass it a keyring so that it can lookup private and public keys
// as necessary. Returns the MessageKeyInfo recovered during header
// processing, an io.Reader stream from which you can read the plaintext, the armor branding, and
// maybe an error if there was a failure. | [
"NewDearmor62SigncryptOpenStream",
"makes",
"a",
"new",
"stream",
"that",
"dearmors",
"and",
"decrypts",
"the",
"given",
"Reader",
"stream",
".",
"Pass",
"it",
"a",
"keyring",
"so",
"that",
"it",
"can",
"lookup",
"private",
"and",
"public",
"keys",
"as",
"necessary",
".",
"Returns",
"the",
"MessageKeyInfo",
"recovered",
"during",
"header",
"processing",
"an",
"io",
".",
"Reader",
"stream",
"from",
"which",
"you",
"can",
"read",
"the",
"plaintext",
"the",
"armor",
"branding",
"and",
"maybe",
"an",
"error",
"if",
"there",
"was",
"a",
"failure",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/armor62_signcrypt.go#L80-L94 |
1,408 | keybase/saltpack | decrypt.go | NewDecryptStream | func NewDecryptStream(versionValidator VersionValidator, r io.Reader, keyring Keyring) (mki *MessageKeyInfo, plaintext io.Reader, err error) {
ds := &decryptStream{
versionValidator: versionValidator,
ring: keyring,
mps: newMsgpackStream(r),
}
err = ds.readHeader(r)
if err != nil {
return &ds.mki, nil, err
}
return &ds.mki, newChunkReader(ds), nil
} | go | func NewDecryptStream(versionValidator VersionValidator, r io.Reader, keyring Keyring) (mki *MessageKeyInfo, plaintext io.Reader, err error) {
ds := &decryptStream{
versionValidator: versionValidator,
ring: keyring,
mps: newMsgpackStream(r),
}
err = ds.readHeader(r)
if err != nil {
return &ds.mki, nil, err
}
return &ds.mki, newChunkReader(ds), nil
} | [
"func",
"NewDecryptStream",
"(",
"versionValidator",
"VersionValidator",
",",
"r",
"io",
".",
"Reader",
",",
"keyring",
"Keyring",
")",
"(",
"mki",
"*",
"MessageKeyInfo",
",",
"plaintext",
"io",
".",
"Reader",
",",
"err",
"error",
")",
"{",
"ds",
":=",
"&",
"decryptStream",
"{",
"versionValidator",
":",
"versionValidator",
",",
"ring",
":",
"keyring",
",",
"mps",
":",
"newMsgpackStream",
"(",
"r",
")",
",",
"}",
"\n\n",
"err",
"=",
"ds",
".",
"readHeader",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"&",
"ds",
".",
"mki",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"ds",
".",
"mki",
",",
"newChunkReader",
"(",
"ds",
")",
",",
"nil",
"\n",
"}"
] | // NewDecryptStream starts a streaming decryption. It synchronously ingests
// and parses the given Reader's encryption header. It consults the passed
// keyring for the decryption keys needed to decrypt the message. On failure,
// it returns a null Reader and an error message. On success, it returns a
// Reader with the plaintext stream, and a nil error. In either case, it will
// return a `MessageKeyInfo` which tells about who the sender was, and which of the
// Receiver's keys was used to decrypt the message.
//
// Note that the caller has an opportunity not to ingest the plaintext if he
// doesn't trust the sender revealed in the MessageKeyInfo.
// | [
"NewDecryptStream",
"starts",
"a",
"streaming",
"decryption",
".",
"It",
"synchronously",
"ingests",
"and",
"parses",
"the",
"given",
"Reader",
"s",
"encryption",
"header",
".",
"It",
"consults",
"the",
"passed",
"keyring",
"for",
"the",
"decryption",
"keys",
"needed",
"to",
"decrypt",
"the",
"message",
".",
"On",
"failure",
"it",
"returns",
"a",
"null",
"Reader",
"and",
"an",
"error",
"message",
".",
"On",
"success",
"it",
"returns",
"a",
"Reader",
"with",
"the",
"plaintext",
"stream",
"and",
"a",
"nil",
"error",
".",
"In",
"either",
"case",
"it",
"will",
"return",
"a",
"MessageKeyInfo",
"which",
"tells",
"about",
"who",
"the",
"sender",
"was",
"and",
"which",
"of",
"the",
"Receiver",
"s",
"keys",
"was",
"used",
"to",
"decrypt",
"the",
"message",
".",
"Note",
"that",
"the",
"caller",
"has",
"an",
"opportunity",
"not",
"to",
"ingest",
"the",
"plaintext",
"if",
"he",
"doesn",
"t",
"trust",
"the",
"sender",
"revealed",
"in",
"the",
"MessageKeyInfo",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/decrypt.go#L302-L315 |
1,409 | keybase/saltpack | decrypt.go | Open | func Open(versionValidator VersionValidator, ciphertext []byte, keyring Keyring) (i *MessageKeyInfo, plaintext []byte, err error) {
buf := bytes.NewBuffer(ciphertext)
mki, plaintextStream, err := NewDecryptStream(versionValidator, buf, keyring)
if err != nil {
return mki, nil, err
}
ret, err := ioutil.ReadAll(plaintextStream)
if err != nil {
return nil, nil, err
}
return mki, ret, err
} | go | func Open(versionValidator VersionValidator, ciphertext []byte, keyring Keyring) (i *MessageKeyInfo, plaintext []byte, err error) {
buf := bytes.NewBuffer(ciphertext)
mki, plaintextStream, err := NewDecryptStream(versionValidator, buf, keyring)
if err != nil {
return mki, nil, err
}
ret, err := ioutil.ReadAll(plaintextStream)
if err != nil {
return nil, nil, err
}
return mki, ret, err
} | [
"func",
"Open",
"(",
"versionValidator",
"VersionValidator",
",",
"ciphertext",
"[",
"]",
"byte",
",",
"keyring",
"Keyring",
")",
"(",
"i",
"*",
"MessageKeyInfo",
",",
"plaintext",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"ciphertext",
")",
"\n",
"mki",
",",
"plaintextStream",
",",
"err",
":=",
"NewDecryptStream",
"(",
"versionValidator",
",",
"buf",
",",
"keyring",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"mki",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"ret",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"plaintextStream",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"mki",
",",
"ret",
",",
"err",
"\n",
"}"
] | // Open simply opens a ciphertext given the set of keys in the specified keyring.
// It returns a plaintext on success, and an error on failure. It returns the header's
// MessageKeyInfo in either case. | [
"Open",
"simply",
"opens",
"a",
"ciphertext",
"given",
"the",
"set",
"of",
"keys",
"in",
"the",
"specified",
"keyring",
".",
"It",
"returns",
"a",
"plaintext",
"on",
"success",
"and",
"an",
"error",
"on",
"failure",
".",
"It",
"returns",
"the",
"header",
"s",
"MessageKeyInfo",
"in",
"either",
"case",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/decrypt.go#L320-L331 |
1,410 | keybase/saltpack | armor62.go | Armor62Seal | func Armor62Seal(plaintext []byte, typ MessageType, brand string) (string, error) {
hdr := makeFrame(headerMarker, typ, brand)
ftr := makeFrame(footerMarker, typ, brand)
return armorSeal(plaintext, hdr, ftr, Armor62Params)
} | go | func Armor62Seal(plaintext []byte, typ MessageType, brand string) (string, error) {
hdr := makeFrame(headerMarker, typ, brand)
ftr := makeFrame(footerMarker, typ, brand)
return armorSeal(plaintext, hdr, ftr, Armor62Params)
} | [
"func",
"Armor62Seal",
"(",
"plaintext",
"[",
"]",
"byte",
",",
"typ",
"MessageType",
",",
"brand",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"hdr",
":=",
"makeFrame",
"(",
"headerMarker",
",",
"typ",
",",
"brand",
")",
"\n",
"ftr",
":=",
"makeFrame",
"(",
"footerMarker",
",",
"typ",
",",
"brand",
")",
"\n",
"return",
"armorSeal",
"(",
"plaintext",
",",
"hdr",
",",
"ftr",
",",
"Armor62Params",
")",
"\n",
"}"
] | // Armor62Seal takes an input plaintext and returns and output armor encoding
// as a string, or an error if a problem was encountered. Also provide a header
// and a footer to frame the message. Uses Base62 encoding scheme | [
"Armor62Seal",
"takes",
"an",
"input",
"plaintext",
"and",
"returns",
"and",
"output",
"armor",
"encoding",
"as",
"a",
"string",
"or",
"an",
"error",
"if",
"a",
"problem",
"was",
"encountered",
".",
"Also",
"provide",
"a",
"header",
"and",
"a",
"footer",
"to",
"frame",
"the",
"message",
".",
"Uses",
"Base62",
"encoding",
"scheme"
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/armor62.go#L39-L43 |
1,411 | keybase/saltpack | key.go | PublicKeyEqual | func PublicKeyEqual(k1, k2 BasePublicKey) bool {
return hmac.Equal(k1.ToKID(), k2.ToKID())
} | go | func PublicKeyEqual(k1, k2 BasePublicKey) bool {
return hmac.Equal(k1.ToKID(), k2.ToKID())
} | [
"func",
"PublicKeyEqual",
"(",
"k1",
",",
"k2",
"BasePublicKey",
")",
"bool",
"{",
"return",
"hmac",
".",
"Equal",
"(",
"k1",
".",
"ToKID",
"(",
")",
",",
"k2",
".",
"ToKID",
"(",
")",
")",
"\n",
"}"
] | // PublicKeyEqual returns true if the two public keys are equal. | [
"PublicKeyEqual",
"returns",
"true",
"if",
"the",
"two",
"public",
"keys",
"are",
"equal",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/key.go#L152-L154 |
1,412 | keybase/saltpack | common.go | assertEndOfStream | func assertEndOfStream(stream *msgpackStream) error {
var i interface{}
_, err := stream.Read(&i)
if err == nil {
err = ErrTrailingGarbage
}
return err
} | go | func assertEndOfStream(stream *msgpackStream) error {
var i interface{}
_, err := stream.Read(&i)
if err == nil {
err = ErrTrailingGarbage
}
return err
} | [
"func",
"assertEndOfStream",
"(",
"stream",
"*",
"msgpackStream",
")",
"error",
"{",
"var",
"i",
"interface",
"{",
"}",
"\n",
"_",
",",
"err",
":=",
"stream",
".",
"Read",
"(",
"&",
"i",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"ErrTrailingGarbage",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // assertEndOfStream reads from stream, and converts a nil error into
// ErrTrailingGarbage. Thus, it always returns a non-nil error. This
// should be used in a context where io.EOF is expected, and anything
// else is an error. | [
"assertEndOfStream",
"reads",
"from",
"stream",
"and",
"converts",
"a",
"nil",
"error",
"into",
"ErrTrailingGarbage",
".",
"Thus",
"it",
"always",
"returns",
"a",
"non",
"-",
"nil",
"error",
".",
"This",
"should",
"be",
"used",
"in",
"a",
"context",
"where",
"io",
".",
"EOF",
"is",
"expected",
"and",
"anything",
"else",
"is",
"an",
"error",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/common.go#L43-L50 |
1,413 | keybase/saltpack | common.go | CheckKnownMajorVersion | func CheckKnownMajorVersion(version Version) error {
for _, knownVersion := range KnownVersions() {
if version.Major == knownVersion.Major {
return nil
}
}
return ErrBadVersion{version}
} | go | func CheckKnownMajorVersion(version Version) error {
for _, knownVersion := range KnownVersions() {
if version.Major == knownVersion.Major {
return nil
}
}
return ErrBadVersion{version}
} | [
"func",
"CheckKnownMajorVersion",
"(",
"version",
"Version",
")",
"error",
"{",
"for",
"_",
",",
"knownVersion",
":=",
"range",
"KnownVersions",
"(",
")",
"{",
"if",
"version",
".",
"Major",
"==",
"knownVersion",
".",
"Major",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"ErrBadVersion",
"{",
"version",
"}",
"\n",
"}"
] | // CheckKnownMajorVersion returns nil if the given version has a known
// major version. You probably want to use this with NewDecryptStream,
// unless you want to restrict to specific versions only. | [
"CheckKnownMajorVersion",
"returns",
"nil",
"if",
"the",
"given",
"version",
"has",
"a",
"known",
"major",
"version",
".",
"You",
"probably",
"want",
"to",
"use",
"this",
"with",
"NewDecryptStream",
"unless",
"you",
"want",
"to",
"restrict",
"to",
"specific",
"versions",
"only",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/common.go#L215-L222 |
1,414 | keybase/saltpack | common.go | SingleVersionValidator | func SingleVersionValidator(desiredVersion Version) VersionValidator {
return func(version Version) error {
if version == desiredVersion {
return nil
}
return ErrBadVersion{version}
}
} | go | func SingleVersionValidator(desiredVersion Version) VersionValidator {
return func(version Version) error {
if version == desiredVersion {
return nil
}
return ErrBadVersion{version}
}
} | [
"func",
"SingleVersionValidator",
"(",
"desiredVersion",
"Version",
")",
"VersionValidator",
"{",
"return",
"func",
"(",
"version",
"Version",
")",
"error",
"{",
"if",
"version",
"==",
"desiredVersion",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"ErrBadVersion",
"{",
"version",
"}",
"\n",
"}",
"\n",
"}"
] | // SingleVersionValidator returns a VersionValidator that returns nil
// if its given version is equal to desiredVersion. | [
"SingleVersionValidator",
"returns",
"a",
"VersionValidator",
"that",
"returns",
"nil",
"if",
"its",
"given",
"version",
"is",
"equal",
"to",
"desiredVersion",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/common.go#L226-L234 |
1,415 | keybase/saltpack | common.go | assertEncodedChunkState | func assertEncodedChunkState(version Version, encodedChunk []byte, encodingOverhead int, blockIndex uint64, isFinal bool) {
if len(encodedChunk) < encodingOverhead {
panic("encodedChunk is too small")
}
err := checkChunkState(version, len(encodedChunk)-encodingOverhead, blockIndex, isFinal)
if err != nil {
panic(err)
}
} | go | func assertEncodedChunkState(version Version, encodedChunk []byte, encodingOverhead int, blockIndex uint64, isFinal bool) {
if len(encodedChunk) < encodingOverhead {
panic("encodedChunk is too small")
}
err := checkChunkState(version, len(encodedChunk)-encodingOverhead, blockIndex, isFinal)
if err != nil {
panic(err)
}
} | [
"func",
"assertEncodedChunkState",
"(",
"version",
"Version",
",",
"encodedChunk",
"[",
"]",
"byte",
",",
"encodingOverhead",
"int",
",",
"blockIndex",
"uint64",
",",
"isFinal",
"bool",
")",
"{",
"if",
"len",
"(",
"encodedChunk",
")",
"<",
"encodingOverhead",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"err",
":=",
"checkChunkState",
"(",
"version",
",",
"len",
"(",
"encodedChunk",
")",
"-",
"encodingOverhead",
",",
"blockIndex",
",",
"isFinal",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"}"
] | // assertEncodedChunkState sanity-checks some encoded chunk parameters. | [
"assertEncodedChunkState",
"sanity",
"-",
"checks",
"some",
"encoded",
"chunk",
"parameters",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/common.go#L260-L269 |
1,416 | keybase/saltpack | common.go | checkDecodedChunkState | func checkDecodedChunkState(version Version, chunk []byte, seqno packetSeqno, isFinal bool) error {
// The first decoded block has seqno 1, since the header bytes
// are decoded first.
return checkChunkState(version, len(chunk), uint64(seqno-1), isFinal)
} | go | func checkDecodedChunkState(version Version, chunk []byte, seqno packetSeqno, isFinal bool) error {
// The first decoded block has seqno 1, since the header bytes
// are decoded first.
return checkChunkState(version, len(chunk), uint64(seqno-1), isFinal)
} | [
"func",
"checkDecodedChunkState",
"(",
"version",
"Version",
",",
"chunk",
"[",
"]",
"byte",
",",
"seqno",
"packetSeqno",
",",
"isFinal",
"bool",
")",
"error",
"{",
"// The first decoded block has seqno 1, since the header bytes",
"// are decoded first.",
"return",
"checkChunkState",
"(",
"version",
",",
"len",
"(",
"chunk",
")",
",",
"uint64",
"(",
"seqno",
"-",
"1",
")",
",",
"isFinal",
")",
"\n",
"}"
] | // checkDecodedChunkState sanity-checks some decoded chunk
// parameters. A returned error means there's something wrong with the
// decoded stream. | [
"checkDecodedChunkState",
"sanity",
"-",
"checks",
"some",
"decoded",
"chunk",
"parameters",
".",
"A",
"returned",
"error",
"means",
"there",
"s",
"something",
"wrong",
"with",
"the",
"decoded",
"stream",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/common.go#L274-L278 |
1,417 | keybase/saltpack | encoding/basex/encoding.go | IsValidByte | func (enc *Encoding) IsValidByte(b byte) bool {
return enc.decodeMap[b] != nil || enc.skipMap[b]
} | go | func (enc *Encoding) IsValidByte(b byte) bool {
return enc.decodeMap[b] != nil || enc.skipMap[b]
} | [
"func",
"(",
"enc",
"*",
"Encoding",
")",
"IsValidByte",
"(",
"b",
"byte",
")",
"bool",
"{",
"return",
"enc",
".",
"decodeMap",
"[",
"b",
"]",
"!=",
"nil",
"||",
"enc",
".",
"skipMap",
"[",
"b",
"]",
"\n",
"}"
] | // IsValidByte returns true if the given byte is valid in this
// decoding. Can be either from the main alphabet or the skip
// alphabet to be considered valid. | [
"IsValidByte",
"returns",
"true",
"if",
"the",
"given",
"byte",
"is",
"valid",
"in",
"this",
"decoding",
".",
"Can",
"be",
"either",
"from",
"the",
"main",
"alphabet",
"or",
"the",
"skip",
"alphabet",
"to",
"be",
"considered",
"valid",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/encoding/basex/encoding.go#L118-L120 |
1,418 | keybase/saltpack | encoding/basex/encoding.go | encodeBlock | func (enc *Encoding) encodeBlock(dst, src []byte) {
// Interpret the block as a big-endian number (Go's default)
num := new(big.Int).SetBytes(src)
rem := new(big.Int)
quo := new(big.Int)
encodedLen := enc.EncodedLen(len(src))
p := encodedLen - 1
for num.Sign() != 0 {
num, rem = quo.QuoRem(num, enc.baseBig, rem)
dst[p] = enc.encode[rem.Uint64()]
p--
}
// Pad the remainder of the buffer with 0s
for p >= 0 {
dst[p] = enc.encode[0]
p--
}
} | go | func (enc *Encoding) encodeBlock(dst, src []byte) {
// Interpret the block as a big-endian number (Go's default)
num := new(big.Int).SetBytes(src)
rem := new(big.Int)
quo := new(big.Int)
encodedLen := enc.EncodedLen(len(src))
p := encodedLen - 1
for num.Sign() != 0 {
num, rem = quo.QuoRem(num, enc.baseBig, rem)
dst[p] = enc.encode[rem.Uint64()]
p--
}
// Pad the remainder of the buffer with 0s
for p >= 0 {
dst[p] = enc.encode[0]
p--
}
} | [
"func",
"(",
"enc",
"*",
"Encoding",
")",
"encodeBlock",
"(",
"dst",
",",
"src",
"[",
"]",
"byte",
")",
"{",
"// Interpret the block as a big-endian number (Go's default)",
"num",
":=",
"new",
"(",
"big",
".",
"Int",
")",
".",
"SetBytes",
"(",
"src",
")",
"\n",
"rem",
":=",
"new",
"(",
"big",
".",
"Int",
")",
"\n",
"quo",
":=",
"new",
"(",
"big",
".",
"Int",
")",
"\n\n",
"encodedLen",
":=",
"enc",
".",
"EncodedLen",
"(",
"len",
"(",
"src",
")",
")",
"\n\n",
"p",
":=",
"encodedLen",
"-",
"1",
"\n\n",
"for",
"num",
".",
"Sign",
"(",
")",
"!=",
"0",
"{",
"num",
",",
"rem",
"=",
"quo",
".",
"QuoRem",
"(",
"num",
",",
"enc",
".",
"baseBig",
",",
"rem",
")",
"\n",
"dst",
"[",
"p",
"]",
"=",
"enc",
".",
"encode",
"[",
"rem",
".",
"Uint64",
"(",
")",
"]",
"\n",
"p",
"--",
"\n",
"}",
"\n\n",
"// Pad the remainder of the buffer with 0s",
"for",
"p",
">=",
"0",
"{",
"dst",
"[",
"p",
"]",
"=",
"enc",
".",
"encode",
"[",
"0",
"]",
"\n",
"p",
"--",
"\n",
"}",
"\n",
"}"
] | // encodeBlock fills the dst buffer with the encoding of src.
// It is assumed the buffers are appropriately sized, and no
// bounds checks are performed. In particular, the dst buffer will
// be zero-padded from right to left in all remaining bytes. | [
"encodeBlock",
"fills",
"the",
"dst",
"buffer",
"with",
"the",
"encoding",
"of",
"src",
".",
"It",
"is",
"assumed",
"the",
"buffers",
"are",
"appropriately",
"sized",
"and",
"no",
"bounds",
"checks",
"are",
"performed",
".",
"In",
"particular",
"the",
"dst",
"buffer",
"will",
"be",
"zero",
"-",
"padded",
"from",
"right",
"to",
"left",
"in",
"all",
"remaining",
"bytes",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/encoding/basex/encoding.go#L126-L148 |
1,419 | keybase/saltpack | encoding/basex/encoding.go | EncodedLen | func (enc *Encoding) EncodedLen(n int) int {
// Fast path!
if n == enc.base256BlockLen {
return enc.baseXBlockLen
}
nblocks := n / enc.base256BlockLen
out := nblocks * enc.baseXBlockLen
rem := n % enc.base256BlockLen
if rem > 0 {
out += int(math.Ceil(float64(rem*8) / enc.logOfBase))
}
return out
} | go | func (enc *Encoding) EncodedLen(n int) int {
// Fast path!
if n == enc.base256BlockLen {
return enc.baseXBlockLen
}
nblocks := n / enc.base256BlockLen
out := nblocks * enc.baseXBlockLen
rem := n % enc.base256BlockLen
if rem > 0 {
out += int(math.Ceil(float64(rem*8) / enc.logOfBase))
}
return out
} | [
"func",
"(",
"enc",
"*",
"Encoding",
")",
"EncodedLen",
"(",
"n",
"int",
")",
"int",
"{",
"// Fast path!",
"if",
"n",
"==",
"enc",
".",
"base256BlockLen",
"{",
"return",
"enc",
".",
"baseXBlockLen",
"\n",
"}",
"\n\n",
"nblocks",
":=",
"n",
"/",
"enc",
".",
"base256BlockLen",
"\n",
"out",
":=",
"nblocks",
"*",
"enc",
".",
"baseXBlockLen",
"\n",
"rem",
":=",
"n",
"%",
"enc",
".",
"base256BlockLen",
"\n",
"if",
"rem",
">",
"0",
"{",
"out",
"+=",
"int",
"(",
"math",
".",
"Ceil",
"(",
"float64",
"(",
"rem",
"*",
"8",
")",
"/",
"enc",
".",
"logOfBase",
")",
")",
"\n",
"}",
"\n",
"return",
"out",
"\n",
"}"
] | // EncodedLen returns the length in bytes of the baseX encoding
// of an input buffer of length n | [
"EncodedLen",
"returns",
"the",
"length",
"in",
"bytes",
"of",
"the",
"baseX",
"encoding",
"of",
"an",
"input",
"buffer",
"of",
"length",
"n"
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/encoding/basex/encoding.go#L229-L243 |
1,420 | keybase/saltpack | encoding/basex/encoding.go | DecodedLen | func (enc *Encoding) DecodedLen(n int) int {
// Fast path!
if n == enc.baseXBlockLen {
return enc.base256BlockLen
}
nblocks := n / enc.baseXBlockLen
out := nblocks * enc.base256BlockLen
rem := n % enc.baseXBlockLen
if rem > 0 {
out += int(math.Floor(float64(rem) * enc.logOfBase / float64(8)))
}
return out
} | go | func (enc *Encoding) DecodedLen(n int) int {
// Fast path!
if n == enc.baseXBlockLen {
return enc.base256BlockLen
}
nblocks := n / enc.baseXBlockLen
out := nblocks * enc.base256BlockLen
rem := n % enc.baseXBlockLen
if rem > 0 {
out += int(math.Floor(float64(rem) * enc.logOfBase / float64(8)))
}
return out
} | [
"func",
"(",
"enc",
"*",
"Encoding",
")",
"DecodedLen",
"(",
"n",
"int",
")",
"int",
"{",
"// Fast path!",
"if",
"n",
"==",
"enc",
".",
"baseXBlockLen",
"{",
"return",
"enc",
".",
"base256BlockLen",
"\n",
"}",
"\n\n",
"nblocks",
":=",
"n",
"/",
"enc",
".",
"baseXBlockLen",
"\n",
"out",
":=",
"nblocks",
"*",
"enc",
".",
"base256BlockLen",
"\n",
"rem",
":=",
"n",
"%",
"enc",
".",
"baseXBlockLen",
"\n",
"if",
"rem",
">",
"0",
"{",
"out",
"+=",
"int",
"(",
"math",
".",
"Floor",
"(",
"float64",
"(",
"rem",
")",
"*",
"enc",
".",
"logOfBase",
"/",
"float64",
"(",
"8",
")",
")",
")",
"\n",
"}",
"\n",
"return",
"out",
"\n",
"}"
] | // DecodedLen returns the length in bytes of the baseX decoding
// of an input buffer of length n | [
"DecodedLen",
"returns",
"the",
"length",
"in",
"bytes",
"of",
"the",
"baseX",
"decoding",
"of",
"an",
"input",
"buffer",
"of",
"length",
"n"
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/encoding/basex/encoding.go#L247-L261 |
1,421 | keybase/saltpack | encoding/basex/encoding.go | IsValidEncodingLength | func (enc *Encoding) IsValidEncodingLength(n int) bool {
// Fast path!
if n == enc.baseXBlockLen {
return true
}
f := func(n int) int {
return int(math.Floor(float64(n) * enc.logOfBase / float64(8)))
}
if f(n) == f(n-1) {
return false
}
return true
} | go | func (enc *Encoding) IsValidEncodingLength(n int) bool {
// Fast path!
if n == enc.baseXBlockLen {
return true
}
f := func(n int) int {
return int(math.Floor(float64(n) * enc.logOfBase / float64(8)))
}
if f(n) == f(n-1) {
return false
}
return true
} | [
"func",
"(",
"enc",
"*",
"Encoding",
")",
"IsValidEncodingLength",
"(",
"n",
"int",
")",
"bool",
"{",
"// Fast path!",
"if",
"n",
"==",
"enc",
".",
"baseXBlockLen",
"{",
"return",
"true",
"\n",
"}",
"\n",
"f",
":=",
"func",
"(",
"n",
"int",
")",
"int",
"{",
"return",
"int",
"(",
"math",
".",
"Floor",
"(",
"float64",
"(",
"n",
")",
"*",
"enc",
".",
"logOfBase",
"/",
"float64",
"(",
"8",
")",
")",
")",
"\n",
"}",
"\n",
"if",
"f",
"(",
"n",
")",
"==",
"f",
"(",
"n",
"-",
"1",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // IsValidEncodingLength returns true if this block has a valid encoding length.
// An encoding length is invalid if a short encoding would have sufficed. | [
"IsValidEncodingLength",
"returns",
"true",
"if",
"this",
"block",
"has",
"a",
"valid",
"encoding",
"length",
".",
"An",
"encoding",
"length",
"is",
"invalid",
"if",
"a",
"short",
"encoding",
"would",
"have",
"sufficed",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/encoding/basex/encoding.go#L265-L277 |
1,422 | keybase/saltpack | sign.go | NewSignStream | func NewSignStream(version Version, signedtext io.Writer, signer SigningSecretKey) (stream io.WriteCloser, err error) {
return newSignAttachedStream(version, signedtext, signer)
} | go | func NewSignStream(version Version, signedtext io.Writer, signer SigningSecretKey) (stream io.WriteCloser, err error) {
return newSignAttachedStream(version, signedtext, signer)
} | [
"func",
"NewSignStream",
"(",
"version",
"Version",
",",
"signedtext",
"io",
".",
"Writer",
",",
"signer",
"SigningSecretKey",
")",
"(",
"stream",
"io",
".",
"WriteCloser",
",",
"err",
"error",
")",
"{",
"return",
"newSignAttachedStream",
"(",
"version",
",",
"signedtext",
",",
"signer",
")",
"\n",
"}"
] | // NewSignStream creates a stream that consumes plaintext data.
// It will write out signed data to the io.Writer passed in as
// signedtext. NewSignStream only generates attached signatures. | [
"NewSignStream",
"creates",
"a",
"stream",
"that",
"consumes",
"plaintext",
"data",
".",
"It",
"will",
"write",
"out",
"signed",
"data",
"to",
"the",
"io",
".",
"Writer",
"passed",
"in",
"as",
"signedtext",
".",
"NewSignStream",
"only",
"generates",
"attached",
"signatures",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/sign.go#L14-L16 |
1,423 | keybase/saltpack | sign.go | Sign | func Sign(version Version, plaintext []byte, signer SigningSecretKey) ([]byte, error) {
buf, err := signToStream(version, plaintext, signer, NewSignStream)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
} | go | func Sign(version Version, plaintext []byte, signer SigningSecretKey) ([]byte, error) {
buf, err := signToStream(version, plaintext, signer, NewSignStream)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
} | [
"func",
"Sign",
"(",
"version",
"Version",
",",
"plaintext",
"[",
"]",
"byte",
",",
"signer",
"SigningSecretKey",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"buf",
",",
"err",
":=",
"signToStream",
"(",
"version",
",",
"plaintext",
",",
"signer",
",",
"NewSignStream",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"buf",
".",
"Bytes",
"(",
")",
",",
"nil",
"\n",
"}"
] | // Sign creates an attached signature message of plaintext from signer. | [
"Sign",
"creates",
"an",
"attached",
"signature",
"message",
"of",
"plaintext",
"from",
"signer",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/sign.go#L19-L25 |
1,424 | keybase/saltpack | sign.go | NewSignDetachedStream | func NewSignDetachedStream(version Version, detachedsig io.Writer, signer SigningSecretKey) (stream io.WriteCloser, err error) {
return newSignDetachedStream(version, detachedsig, signer)
} | go | func NewSignDetachedStream(version Version, detachedsig io.Writer, signer SigningSecretKey) (stream io.WriteCloser, err error) {
return newSignDetachedStream(version, detachedsig, signer)
} | [
"func",
"NewSignDetachedStream",
"(",
"version",
"Version",
",",
"detachedsig",
"io",
".",
"Writer",
",",
"signer",
"SigningSecretKey",
")",
"(",
"stream",
"io",
".",
"WriteCloser",
",",
"err",
"error",
")",
"{",
"return",
"newSignDetachedStream",
"(",
"version",
",",
"detachedsig",
",",
"signer",
")",
"\n",
"}"
] | // NewSignDetachedStream creates a stream that consumes plaintext
// data. It will write out a detached signature to the io.Writer
// passed in as detachedsig. | [
"NewSignDetachedStream",
"creates",
"a",
"stream",
"that",
"consumes",
"plaintext",
"data",
".",
"It",
"will",
"write",
"out",
"a",
"detached",
"signature",
"to",
"the",
"io",
".",
"Writer",
"passed",
"in",
"as",
"detachedsig",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/sign.go#L30-L32 |
1,425 | keybase/saltpack | sign.go | SignDetached | func SignDetached(version Version, plaintext []byte, signer SigningSecretKey) ([]byte, error) {
buf, err := signToStream(version, plaintext, signer, NewSignDetachedStream)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
} | go | func SignDetached(version Version, plaintext []byte, signer SigningSecretKey) ([]byte, error) {
buf, err := signToStream(version, plaintext, signer, NewSignDetachedStream)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
} | [
"func",
"SignDetached",
"(",
"version",
"Version",
",",
"plaintext",
"[",
"]",
"byte",
",",
"signer",
"SigningSecretKey",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"buf",
",",
"err",
":=",
"signToStream",
"(",
"version",
",",
"plaintext",
",",
"signer",
",",
"NewSignDetachedStream",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"buf",
".",
"Bytes",
"(",
")",
",",
"nil",
"\n",
"}"
] | // SignDetached returns a detached signature of plaintext from
// signer. | [
"SignDetached",
"returns",
"a",
"detached",
"signature",
"of",
"plaintext",
"from",
"signer",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/sign.go#L36-L42 |
1,426 | keybase/saltpack | sign.go | signToStream | func signToStream(version Version, plaintext []byte, signer SigningSecretKey, streamer func(Version, io.Writer, SigningSecretKey) (io.WriteCloser, error)) (*bytes.Buffer, error) {
var buf bytes.Buffer
s, err := streamer(version, &buf, signer)
if err != nil {
return nil, err
}
if _, err := s.Write(plaintext); err != nil {
return nil, err
}
if err := s.Close(); err != nil {
return nil, err
}
return &buf, nil
} | go | func signToStream(version Version, plaintext []byte, signer SigningSecretKey, streamer func(Version, io.Writer, SigningSecretKey) (io.WriteCloser, error)) (*bytes.Buffer, error) {
var buf bytes.Buffer
s, err := streamer(version, &buf, signer)
if err != nil {
return nil, err
}
if _, err := s.Write(plaintext); err != nil {
return nil, err
}
if err := s.Close(); err != nil {
return nil, err
}
return &buf, nil
} | [
"func",
"signToStream",
"(",
"version",
"Version",
",",
"plaintext",
"[",
"]",
"byte",
",",
"signer",
"SigningSecretKey",
",",
"streamer",
"func",
"(",
"Version",
",",
"io",
".",
"Writer",
",",
"SigningSecretKey",
")",
"(",
"io",
".",
"WriteCloser",
",",
"error",
")",
")",
"(",
"*",
"bytes",
".",
"Buffer",
",",
"error",
")",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"s",
",",
"err",
":=",
"streamer",
"(",
"version",
",",
"&",
"buf",
",",
"signer",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"s",
".",
"Write",
"(",
"plaintext",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"s",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"buf",
",",
"nil",
"\n",
"}"
] | // signToStream creates a signature for plaintext with signer,
// using streamer to generate a signing stream. | [
"signToStream",
"creates",
"a",
"signature",
"for",
"plaintext",
"with",
"signer",
"using",
"streamer",
"to",
"generate",
"a",
"signing",
"stream",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/sign.go#L46-L60 |
1,427 | keybase/saltpack | frame.go | MakeArmorHeader | func MakeArmorHeader(typ MessageType, brand string) string {
return makeFrame(headerMarker, typ, brand)
} | go | func MakeArmorHeader(typ MessageType, brand string) string {
return makeFrame(headerMarker, typ, brand)
} | [
"func",
"MakeArmorHeader",
"(",
"typ",
"MessageType",
",",
"brand",
"string",
")",
"string",
"{",
"return",
"makeFrame",
"(",
"headerMarker",
",",
"typ",
",",
"brand",
")",
"\n",
"}"
] | // MakeArmorHeader makes the armor header for the message type for the given "brand" | [
"MakeArmorHeader",
"makes",
"the",
"armor",
"header",
"for",
"the",
"message",
"type",
"for",
"the",
"given",
"brand"
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/frame.go#L48-L50 |
1,428 | keybase/saltpack | frame.go | MakeArmorFooter | func MakeArmorFooter(typ MessageType, brand string) string {
return makeFrame(footerMarker, typ, brand)
} | go | func MakeArmorFooter(typ MessageType, brand string) string {
return makeFrame(footerMarker, typ, brand)
} | [
"func",
"MakeArmorFooter",
"(",
"typ",
"MessageType",
",",
"brand",
"string",
")",
"string",
"{",
"return",
"makeFrame",
"(",
"footerMarker",
",",
"typ",
",",
"brand",
")",
"\n",
"}"
] | // MakeArmorFooter makes the armor footer for the message type for the given "brand" | [
"MakeArmorFooter",
"makes",
"the",
"armor",
"footer",
"for",
"the",
"message",
"type",
"for",
"the",
"given",
"brand"
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/frame.go#L53-L55 |
1,429 | keybase/saltpack | encrypt.go | receiversToEphemeralKeyCreator | func receiversToEphemeralKeyCreator(receivers []BoxPublicKey) (EphemeralKeyCreator, error) {
if len(receivers) == 0 {
return nil, ErrBadReceivers
}
return receivers[0], nil
} | go | func receiversToEphemeralKeyCreator(receivers []BoxPublicKey) (EphemeralKeyCreator, error) {
if len(receivers) == 0 {
return nil, ErrBadReceivers
}
return receivers[0], nil
} | [
"func",
"receiversToEphemeralKeyCreator",
"(",
"receivers",
"[",
"]",
"BoxPublicKey",
")",
"(",
"EphemeralKeyCreator",
",",
"error",
")",
"{",
"if",
"len",
"(",
"receivers",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"ErrBadReceivers",
"\n",
"}",
"\n",
"return",
"receivers",
"[",
"0",
"]",
",",
"nil",
"\n",
"}"
] | // receiversToEphemeralKeyCreator retrieves the EphemeralKeyCreator
// from the first receiver; this is to preserve API behavior. | [
"receiversToEphemeralKeyCreator",
"retrieves",
"the",
"EphemeralKeyCreator",
"from",
"the",
"first",
"receiver",
";",
"this",
"is",
"to",
"preserve",
"API",
"behavior",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/encrypt.go#L360-L365 |
1,430 | keybase/saltpack | encrypt.go | NewEncryptStream | func NewEncryptStream(version Version, ciphertext io.Writer, sender BoxSecretKey, receivers []BoxPublicKey) (io.WriteCloser, error) {
ephemeralKeyCreator, err := receiversToEphemeralKeyCreator(receivers)
if err != nil {
return nil, err
}
return newEncryptStream(version, ciphertext, sender, receivers, ephemeralKeyCreator, defaultEncryptRNG{})
} | go | func NewEncryptStream(version Version, ciphertext io.Writer, sender BoxSecretKey, receivers []BoxPublicKey) (io.WriteCloser, error) {
ephemeralKeyCreator, err := receiversToEphemeralKeyCreator(receivers)
if err != nil {
return nil, err
}
return newEncryptStream(version, ciphertext, sender, receivers, ephemeralKeyCreator, defaultEncryptRNG{})
} | [
"func",
"NewEncryptStream",
"(",
"version",
"Version",
",",
"ciphertext",
"io",
".",
"Writer",
",",
"sender",
"BoxSecretKey",
",",
"receivers",
"[",
"]",
"BoxPublicKey",
")",
"(",
"io",
".",
"WriteCloser",
",",
"error",
")",
"{",
"ephemeralKeyCreator",
",",
"err",
":=",
"receiversToEphemeralKeyCreator",
"(",
"receivers",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newEncryptStream",
"(",
"version",
",",
"ciphertext",
",",
"sender",
",",
"receivers",
",",
"ephemeralKeyCreator",
",",
"defaultEncryptRNG",
"{",
"}",
")",
"\n",
"}"
] | // NewEncryptStream creates a stream that consumes plaintext data.
// It will write out encrypted data to the io.Writer passed in as ciphertext.
// The encryption is from the specified sender, and is encrypted for the
// given receivers.
//
// If initialization succeeds, returns an io.WriteCloser that accepts
// plaintext data to be encrypted and a nil error. Otherwise, returns
// nil and the initialization error. | [
"NewEncryptStream",
"creates",
"a",
"stream",
"that",
"consumes",
"plaintext",
"data",
".",
"It",
"will",
"write",
"out",
"encrypted",
"data",
"to",
"the",
"io",
".",
"Writer",
"passed",
"in",
"as",
"ciphertext",
".",
"The",
"encryption",
"is",
"from",
"the",
"specified",
"sender",
"and",
"is",
"encrypted",
"for",
"the",
"given",
"receivers",
".",
"If",
"initialization",
"succeeds",
"returns",
"an",
"io",
".",
"WriteCloser",
"that",
"accepts",
"plaintext",
"data",
"to",
"be",
"encrypted",
"and",
"a",
"nil",
"error",
".",
"Otherwise",
"returns",
"nil",
"and",
"the",
"initialization",
"error",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/encrypt.go#L375-L381 |
1,431 | keybase/saltpack | encrypt.go | Seal | func Seal(version Version, plaintext []byte, sender BoxSecretKey, receivers []BoxPublicKey) (out []byte, err error) {
ephemeralKeyCreator, err := receiversToEphemeralKeyCreator(receivers)
if err != nil {
return nil, err
}
return seal(version, plaintext, sender, receivers, ephemeralKeyCreator, defaultEncryptRNG{})
} | go | func Seal(version Version, plaintext []byte, sender BoxSecretKey, receivers []BoxPublicKey) (out []byte, err error) {
ephemeralKeyCreator, err := receiversToEphemeralKeyCreator(receivers)
if err != nil {
return nil, err
}
return seal(version, plaintext, sender, receivers, ephemeralKeyCreator, defaultEncryptRNG{})
} | [
"func",
"Seal",
"(",
"version",
"Version",
",",
"plaintext",
"[",
"]",
"byte",
",",
"sender",
"BoxSecretKey",
",",
"receivers",
"[",
"]",
"BoxPublicKey",
")",
"(",
"out",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"ephemeralKeyCreator",
",",
"err",
":=",
"receiversToEphemeralKeyCreator",
"(",
"receivers",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"seal",
"(",
"version",
",",
"plaintext",
",",
"sender",
",",
"receivers",
",",
"ephemeralKeyCreator",
",",
"defaultEncryptRNG",
"{",
"}",
")",
"\n",
"}"
] | // Seal a plaintext from the given sender, for the specified receiver groups.
// Returns a ciphertext, or an error if something bad happened. | [
"Seal",
"a",
"plaintext",
"from",
"the",
"given",
"sender",
"for",
"the",
"specified",
"receiver",
"groups",
".",
"Returns",
"a",
"ciphertext",
"or",
"an",
"error",
"if",
"something",
"bad",
"happened",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/encrypt.go#L400-L406 |
1,432 | keybase/saltpack | nonce.go | nonceForChunkSecretBox | func nonceForChunkSecretBox(i encryptionBlockNumber) Nonce {
var n Nonce
copyEqualSizeStr(n[0:16], "saltpack_ploadsb")
binary.BigEndian.PutUint64(n[16:], uint64(i))
return n
} | go | func nonceForChunkSecretBox(i encryptionBlockNumber) Nonce {
var n Nonce
copyEqualSizeStr(n[0:16], "saltpack_ploadsb")
binary.BigEndian.PutUint64(n[16:], uint64(i))
return n
} | [
"func",
"nonceForChunkSecretBox",
"(",
"i",
"encryptionBlockNumber",
")",
"Nonce",
"{",
"var",
"n",
"Nonce",
"\n",
"copyEqualSizeStr",
"(",
"n",
"[",
"0",
":",
"16",
"]",
",",
"\"",
"\"",
")",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint64",
"(",
"n",
"[",
"16",
":",
"]",
",",
"uint64",
"(",
"i",
")",
")",
"\n",
"return",
"n",
"\n",
"}"
] | // Construct the nonce for the ith block of encryption payload. | [
"Construct",
"the",
"nonce",
"for",
"the",
"ith",
"block",
"of",
"encryption",
"payload",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/nonce.go#L63-L68 |
1,433 | keybase/saltpack | nonce.go | nonceForChunkSigncryption | func nonceForChunkSigncryption(headerHash headerHash, isFinal bool, i encryptionBlockNumber) Nonce {
var n Nonce
off := len(n) - 8
copyEqualSize(n[:off], headerHash[:off])
// Set LSB of last byte based on isFinal.
n[off-1] &^= 1
if isFinal {
n[off-1] |= 1
}
binary.BigEndian.PutUint64(n[off:], uint64(i))
return n
} | go | func nonceForChunkSigncryption(headerHash headerHash, isFinal bool, i encryptionBlockNumber) Nonce {
var n Nonce
off := len(n) - 8
copyEqualSize(n[:off], headerHash[:off])
// Set LSB of last byte based on isFinal.
n[off-1] &^= 1
if isFinal {
n[off-1] |= 1
}
binary.BigEndian.PutUint64(n[off:], uint64(i))
return n
} | [
"func",
"nonceForChunkSigncryption",
"(",
"headerHash",
"headerHash",
",",
"isFinal",
"bool",
",",
"i",
"encryptionBlockNumber",
")",
"Nonce",
"{",
"var",
"n",
"Nonce",
"\n",
"off",
":=",
"len",
"(",
"n",
")",
"-",
"8",
"\n",
"copyEqualSize",
"(",
"n",
"[",
":",
"off",
"]",
",",
"headerHash",
"[",
":",
"off",
"]",
")",
"\n",
"// Set LSB of last byte based on isFinal.",
"n",
"[",
"off",
"-",
"1",
"]",
"&^=",
"1",
"\n",
"if",
"isFinal",
"{",
"n",
"[",
"off",
"-",
"1",
"]",
"|=",
"1",
"\n",
"}",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint64",
"(",
"n",
"[",
"off",
":",
"]",
",",
"uint64",
"(",
"i",
")",
")",
"\n",
"return",
"n",
"\n",
"}"
] | // Construct the nonce for the ith block of signcryption
// payload. | [
"Construct",
"the",
"nonce",
"for",
"the",
"ith",
"block",
"of",
"signcryption",
"payload",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/nonce.go#L72-L83 |
1,434 | keybase/saltpack | nonce.go | newSigNonce | func newSigNonce() (sigNonce, error) {
var n sigNonce
if err := csprngRead(n[:]); err != nil {
return sigNonce{}, err
}
return n, nil
} | go | func newSigNonce() (sigNonce, error) {
var n sigNonce
if err := csprngRead(n[:]); err != nil {
return sigNonce{}, err
}
return n, nil
} | [
"func",
"newSigNonce",
"(",
")",
"(",
"sigNonce",
",",
"error",
")",
"{",
"var",
"n",
"sigNonce",
"\n",
"if",
"err",
":=",
"csprngRead",
"(",
"n",
"[",
":",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"sigNonce",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"n",
",",
"nil",
"\n",
"}"
] | // newSigNonce creates a sigNonce with random bytes. | [
"newSigNonce",
"creates",
"a",
"sigNonce",
"with",
"random",
"bytes",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/nonce.go#L89-L95 |
1,435 | keybase/saltpack | basic/key.go | Box | func (k SecretKey) Box(receiver saltpack.BoxPublicKey, nonce saltpack.Nonce, msg []byte) []byte {
ret := box.Seal([]byte{}, msg, (*[24]byte)(&nonce), (*[32]byte)(receiver.ToRawBoxKeyPointer()), (*[32]byte)(&k.sec))
return ret
} | go | func (k SecretKey) Box(receiver saltpack.BoxPublicKey, nonce saltpack.Nonce, msg []byte) []byte {
ret := box.Seal([]byte{}, msg, (*[24]byte)(&nonce), (*[32]byte)(receiver.ToRawBoxKeyPointer()), (*[32]byte)(&k.sec))
return ret
} | [
"func",
"(",
"k",
"SecretKey",
")",
"Box",
"(",
"receiver",
"saltpack",
".",
"BoxPublicKey",
",",
"nonce",
"saltpack",
".",
"Nonce",
",",
"msg",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"ret",
":=",
"box",
".",
"Seal",
"(",
"[",
"]",
"byte",
"{",
"}",
",",
"msg",
",",
"(",
"*",
"[",
"24",
"]",
"byte",
")",
"(",
"&",
"nonce",
")",
",",
"(",
"*",
"[",
"32",
"]",
"byte",
")",
"(",
"receiver",
".",
"ToRawBoxKeyPointer",
"(",
")",
")",
",",
"(",
"*",
"[",
"32",
"]",
"byte",
")",
"(",
"&",
"k",
".",
"sec",
")",
")",
"\n",
"return",
"ret",
"\n",
"}"
] | // Box runs the NaCl box for the given sender and receiver key. | [
"Box",
"runs",
"the",
"NaCl",
"box",
"for",
"the",
"given",
"sender",
"and",
"receiver",
"key",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/basic/key.go#L68-L71 |
1,436 | keybase/saltpack | basic/key.go | Unbox | func (k SecretKey) Unbox(sender saltpack.BoxPublicKey, nonce saltpack.Nonce, msg []byte) ([]byte, error) {
ret, ok := box.Open([]byte{}, msg, (*[24]byte)(&nonce), (*[32]byte)(sender.ToRawBoxKeyPointer()), (*[32]byte)(&k.sec))
if !ok {
return nil, saltpack.ErrDecryptionFailed
}
return ret, nil
} | go | func (k SecretKey) Unbox(sender saltpack.BoxPublicKey, nonce saltpack.Nonce, msg []byte) ([]byte, error) {
ret, ok := box.Open([]byte{}, msg, (*[24]byte)(&nonce), (*[32]byte)(sender.ToRawBoxKeyPointer()), (*[32]byte)(&k.sec))
if !ok {
return nil, saltpack.ErrDecryptionFailed
}
return ret, nil
} | [
"func",
"(",
"k",
"SecretKey",
")",
"Unbox",
"(",
"sender",
"saltpack",
".",
"BoxPublicKey",
",",
"nonce",
"saltpack",
".",
"Nonce",
",",
"msg",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"ret",
",",
"ok",
":=",
"box",
".",
"Open",
"(",
"[",
"]",
"byte",
"{",
"}",
",",
"msg",
",",
"(",
"*",
"[",
"24",
"]",
"byte",
")",
"(",
"&",
"nonce",
")",
",",
"(",
"*",
"[",
"32",
"]",
"byte",
")",
"(",
"sender",
".",
"ToRawBoxKeyPointer",
"(",
")",
")",
",",
"(",
"*",
"[",
"32",
"]",
"byte",
")",
"(",
"&",
"k",
".",
"sec",
")",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"saltpack",
".",
"ErrDecryptionFailed",
"\n",
"}",
"\n",
"return",
"ret",
",",
"nil",
"\n",
"}"
] | // Unbox runs the NaCl unbox operation on the given ciphertext and nonce,
// using the receiver as the secret key. | [
"Unbox",
"runs",
"the",
"NaCl",
"unbox",
"operation",
"on",
"the",
"given",
"ciphertext",
"and",
"nonce",
"using",
"the",
"receiver",
"as",
"the",
"secret",
"key",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/basic/key.go#L75-L81 |
1,437 | keybase/saltpack | basic/key.go | Precompute | func (k SecretKey) Precompute(peer saltpack.BoxPublicKey) saltpack.BoxPrecomputedSharedKey {
var res PrecomputedSharedKey
box.Precompute((*[32]byte)(&res), (*[32]byte)(peer.ToRawBoxKeyPointer()), (*[32]byte)(&k.sec))
return res
} | go | func (k SecretKey) Precompute(peer saltpack.BoxPublicKey) saltpack.BoxPrecomputedSharedKey {
var res PrecomputedSharedKey
box.Precompute((*[32]byte)(&res), (*[32]byte)(peer.ToRawBoxKeyPointer()), (*[32]byte)(&k.sec))
return res
} | [
"func",
"(",
"k",
"SecretKey",
")",
"Precompute",
"(",
"peer",
"saltpack",
".",
"BoxPublicKey",
")",
"saltpack",
".",
"BoxPrecomputedSharedKey",
"{",
"var",
"res",
"PrecomputedSharedKey",
"\n",
"box",
".",
"Precompute",
"(",
"(",
"*",
"[",
"32",
"]",
"byte",
")",
"(",
"&",
"res",
")",
",",
"(",
"*",
"[",
"32",
"]",
"byte",
")",
"(",
"peer",
".",
"ToRawBoxKeyPointer",
"(",
")",
")",
",",
"(",
"*",
"[",
"32",
"]",
"byte",
")",
"(",
"&",
"k",
".",
"sec",
")",
")",
"\n",
"return",
"res",
"\n",
"}"
] | // Precompute computes a shared key with the passed public key. | [
"Precompute",
"computes",
"a",
"shared",
"key",
"with",
"the",
"passed",
"public",
"key",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/basic/key.go#L99-L103 |
1,438 | keybase/saltpack | basic/key.go | NewSecretKey | func NewSecretKey(pub, sec *[32]byte) SecretKey {
return SecretKey{
sec: saltpack.RawBoxKey(*sec),
pub: PublicKey{
RawBoxKey: *pub,
},
}
} | go | func NewSecretKey(pub, sec *[32]byte) SecretKey {
return SecretKey{
sec: saltpack.RawBoxKey(*sec),
pub: PublicKey{
RawBoxKey: *pub,
},
}
} | [
"func",
"NewSecretKey",
"(",
"pub",
",",
"sec",
"*",
"[",
"32",
"]",
"byte",
")",
"SecretKey",
"{",
"return",
"SecretKey",
"{",
"sec",
":",
"saltpack",
".",
"RawBoxKey",
"(",
"*",
"sec",
")",
",",
"pub",
":",
"PublicKey",
"{",
"RawBoxKey",
":",
"*",
"pub",
",",
"}",
",",
"}",
"\n",
"}"
] | // NewSecretKey makes a new SecretKey from the raw 32-byte arrays
// the represent Box public and secret keys. | [
"NewSecretKey",
"makes",
"a",
"new",
"SecretKey",
"from",
"the",
"raw",
"32",
"-",
"byte",
"arrays",
"the",
"represent",
"Box",
"public",
"and",
"secret",
"keys",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/basic/key.go#L107-L114 |
1,439 | keybase/saltpack | basic/key.go | Unbox | func (k PrecomputedSharedKey) Unbox(nonce saltpack.Nonce, msg []byte) ([]byte, error) {
ret, ok := box.OpenAfterPrecomputation([]byte{}, msg, (*[24]byte)(&nonce), (*[32]byte)(&k))
if !ok {
return nil, saltpack.ErrDecryptionFailed
}
return ret, nil
} | go | func (k PrecomputedSharedKey) Unbox(nonce saltpack.Nonce, msg []byte) ([]byte, error) {
ret, ok := box.OpenAfterPrecomputation([]byte{}, msg, (*[24]byte)(&nonce), (*[32]byte)(&k))
if !ok {
return nil, saltpack.ErrDecryptionFailed
}
return ret, nil
} | [
"func",
"(",
"k",
"PrecomputedSharedKey",
")",
"Unbox",
"(",
"nonce",
"saltpack",
".",
"Nonce",
",",
"msg",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"ret",
",",
"ok",
":=",
"box",
".",
"OpenAfterPrecomputation",
"(",
"[",
"]",
"byte",
"{",
"}",
",",
"msg",
",",
"(",
"*",
"[",
"24",
"]",
"byte",
")",
"(",
"&",
"nonce",
")",
",",
"(",
"*",
"[",
"32",
"]",
"byte",
")",
"(",
"&",
"k",
")",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"saltpack",
".",
"ErrDecryptionFailed",
"\n",
"}",
"\n",
"return",
"ret",
",",
"nil",
"\n",
"}"
] | // Unbox runs the unbox computation given a precomputed key. | [
"Unbox",
"runs",
"the",
"unbox",
"computation",
"given",
"a",
"precomputed",
"key",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/basic/key.go#L125-L131 |
1,440 | keybase/saltpack | basic/key.go | NewKeyring | func NewKeyring() *Keyring {
return &Keyring{
encKeys: make(map[PublicKey]SecretKey),
sigKeys: make(map[SigningPublicKey]SigningSecretKey),
}
} | go | func NewKeyring() *Keyring {
return &Keyring{
encKeys: make(map[PublicKey]SecretKey),
sigKeys: make(map[SigningPublicKey]SigningSecretKey),
}
} | [
"func",
"NewKeyring",
"(",
")",
"*",
"Keyring",
"{",
"return",
"&",
"Keyring",
"{",
"encKeys",
":",
"make",
"(",
"map",
"[",
"PublicKey",
"]",
"SecretKey",
")",
",",
"sigKeys",
":",
"make",
"(",
"map",
"[",
"SigningPublicKey",
"]",
"SigningSecretKey",
")",
",",
"}",
"\n",
"}"
] | // NewKeyring makes an empty new basic keyring. | [
"NewKeyring",
"makes",
"an",
"empty",
"new",
"basic",
"keyring",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/basic/key.go#L143-L148 |
1,441 | keybase/saltpack | basic/key.go | ImportBoxKey | func (k *Keyring) ImportBoxKey(pub, sec *[32]byte) {
nk := NewSecretKey(pub, sec)
k.encKeys[nk.pub] = nk
} | go | func (k *Keyring) ImportBoxKey(pub, sec *[32]byte) {
nk := NewSecretKey(pub, sec)
k.encKeys[nk.pub] = nk
} | [
"func",
"(",
"k",
"*",
"Keyring",
")",
"ImportBoxKey",
"(",
"pub",
",",
"sec",
"*",
"[",
"32",
"]",
"byte",
")",
"{",
"nk",
":=",
"NewSecretKey",
"(",
"pub",
",",
"sec",
")",
"\n",
"k",
".",
"encKeys",
"[",
"nk",
".",
"pub",
"]",
"=",
"nk",
"\n",
"}"
] | // ImportBoxKey imports an existing Box key into this keyring, from a raw byte arrays,
// first the public, and then the secret key halves. | [
"ImportBoxKey",
"imports",
"an",
"existing",
"Box",
"key",
"into",
"this",
"keyring",
"from",
"a",
"raw",
"byte",
"arrays",
"first",
"the",
"public",
"and",
"then",
"the",
"secret",
"key",
"halves",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/basic/key.go#L152-L155 |
1,442 | keybase/saltpack | basic/key.go | GenerateBoxKey | func (k *Keyring) GenerateBoxKey() (*SecretKey, error) {
ret, err := generateBoxKey()
if err != nil {
return nil, err
}
k.encKeys[ret.pub] = *ret
return ret, nil
} | go | func (k *Keyring) GenerateBoxKey() (*SecretKey, error) {
ret, err := generateBoxKey()
if err != nil {
return nil, err
}
k.encKeys[ret.pub] = *ret
return ret, nil
} | [
"func",
"(",
"k",
"*",
"Keyring",
")",
"GenerateBoxKey",
"(",
")",
"(",
"*",
"SecretKey",
",",
"error",
")",
"{",
"ret",
",",
"err",
":=",
"generateBoxKey",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"k",
".",
"encKeys",
"[",
"ret",
".",
"pub",
"]",
"=",
"*",
"ret",
"\n",
"return",
"ret",
",",
"nil",
"\n",
"}"
] | // GenerateBoxKey generates a new Box secret key and imports it into the keyring. | [
"GenerateBoxKey",
"generates",
"a",
"new",
"Box",
"secret",
"key",
"and",
"imports",
"it",
"into",
"the",
"keyring",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/basic/key.go#L158-L165 |
1,443 | keybase/saltpack | basic/key.go | GenerateSigningKey | func (k *Keyring) GenerateSigningKey() (*SigningSecretKey, error) {
pub, sec, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
return nil, err
}
if len(pub) != ed25519.PublicKeySize {
panic("unexpected public key size")
}
var pubArray [ed25519.PublicKeySize]byte
copy(pubArray[:], pub)
if len(sec) != ed25519.PrivateKeySize {
panic("unexpected private key size")
}
var privArray [ed25519.PrivateKeySize]byte
copy(privArray[:], sec)
ret := NewSigningSecretKey(&pubArray, &privArray)
return &ret, nil
} | go | func (k *Keyring) GenerateSigningKey() (*SigningSecretKey, error) {
pub, sec, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
return nil, err
}
if len(pub) != ed25519.PublicKeySize {
panic("unexpected public key size")
}
var pubArray [ed25519.PublicKeySize]byte
copy(pubArray[:], pub)
if len(sec) != ed25519.PrivateKeySize {
panic("unexpected private key size")
}
var privArray [ed25519.PrivateKeySize]byte
copy(privArray[:], sec)
ret := NewSigningSecretKey(&pubArray, &privArray)
return &ret, nil
} | [
"func",
"(",
"k",
"*",
"Keyring",
")",
"GenerateSigningKey",
"(",
")",
"(",
"*",
"SigningSecretKey",
",",
"error",
")",
"{",
"pub",
",",
"sec",
",",
"err",
":=",
"ed25519",
".",
"GenerateKey",
"(",
"rand",
".",
"Reader",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"pub",
")",
"!=",
"ed25519",
".",
"PublicKeySize",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"pubArray",
"[",
"ed25519",
".",
"PublicKeySize",
"]",
"byte",
"\n",
"copy",
"(",
"pubArray",
"[",
":",
"]",
",",
"pub",
")",
"\n\n",
"if",
"len",
"(",
"sec",
")",
"!=",
"ed25519",
".",
"PrivateKeySize",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"privArray",
"[",
"ed25519",
".",
"PrivateKeySize",
"]",
"byte",
"\n",
"copy",
"(",
"privArray",
"[",
":",
"]",
",",
"sec",
")",
"\n\n",
"ret",
":=",
"NewSigningSecretKey",
"(",
"&",
"pubArray",
",",
"&",
"privArray",
")",
"\n",
"return",
"&",
"ret",
",",
"nil",
"\n",
"}"
] | // GenerateSigningKey generates a signing key and import it into the keyring. | [
"GenerateSigningKey",
"generates",
"a",
"signing",
"key",
"and",
"import",
"it",
"into",
"the",
"keyring",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/basic/key.go#L168-L188 |
1,444 | keybase/saltpack | basic/key.go | ImportSigningKey | func (k *Keyring) ImportSigningKey(pub *[ed25519.PublicKeySize]byte, sec *[ed25519.PrivateKeySize]byte) {
nk := NewSigningSecretKey(pub, sec)
k.sigKeys[nk.pub] = nk
} | go | func (k *Keyring) ImportSigningKey(pub *[ed25519.PublicKeySize]byte, sec *[ed25519.PrivateKeySize]byte) {
nk := NewSigningSecretKey(pub, sec)
k.sigKeys[nk.pub] = nk
} | [
"func",
"(",
"k",
"*",
"Keyring",
")",
"ImportSigningKey",
"(",
"pub",
"*",
"[",
"ed25519",
".",
"PublicKeySize",
"]",
"byte",
",",
"sec",
"*",
"[",
"ed25519",
".",
"PrivateKeySize",
"]",
"byte",
")",
"{",
"nk",
":=",
"NewSigningSecretKey",
"(",
"pub",
",",
"sec",
")",
"\n",
"k",
".",
"sigKeys",
"[",
"nk",
".",
"pub",
"]",
"=",
"nk",
"\n",
"}"
] | // ImportSigningKey imports the raw signing key into the keyring. | [
"ImportSigningKey",
"imports",
"the",
"raw",
"signing",
"key",
"into",
"the",
"keyring",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/basic/key.go#L191-L194 |
1,445 | keybase/saltpack | basic/key.go | LookupBoxSecretKey | func (k *Keyring) LookupBoxSecretKey(kids [][]byte) (int, saltpack.BoxSecretKey) {
for i, kid := range kids {
if sk, ok := k.encKeys[kidToPublicKey(kid)]; ok {
return i, sk
}
}
return -1, nil
} | go | func (k *Keyring) LookupBoxSecretKey(kids [][]byte) (int, saltpack.BoxSecretKey) {
for i, kid := range kids {
if sk, ok := k.encKeys[kidToPublicKey(kid)]; ok {
return i, sk
}
}
return -1, nil
} | [
"func",
"(",
"k",
"*",
"Keyring",
")",
"LookupBoxSecretKey",
"(",
"kids",
"[",
"]",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"saltpack",
".",
"BoxSecretKey",
")",
"{",
"for",
"i",
",",
"kid",
":=",
"range",
"kids",
"{",
"if",
"sk",
",",
"ok",
":=",
"k",
".",
"encKeys",
"[",
"kidToPublicKey",
"(",
"kid",
")",
"]",
";",
"ok",
"{",
"return",
"i",
",",
"sk",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"-",
"1",
",",
"nil",
"\n",
"}"
] | // LookupBoxSecretKey tries to find one of the secret keys in its keyring
// given the possible key IDs. It returns the index and the key, if found, and -1
// and nil otherwise. | [
"LookupBoxSecretKey",
"tries",
"to",
"find",
"one",
"of",
"the",
"secret",
"keys",
"in",
"its",
"keyring",
"given",
"the",
"possible",
"key",
"IDs",
".",
"It",
"returns",
"the",
"index",
"and",
"the",
"key",
"if",
"found",
"and",
"-",
"1",
"and",
"nil",
"otherwise",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/basic/key.go#L205-L212 |
1,446 | keybase/saltpack | basic/key.go | GetAllBoxSecretKeys | func (k *Keyring) GetAllBoxSecretKeys() []saltpack.BoxSecretKey {
var out []saltpack.BoxSecretKey
for _, v := range k.encKeys {
out = append(out, v)
}
return out
} | go | func (k *Keyring) GetAllBoxSecretKeys() []saltpack.BoxSecretKey {
var out []saltpack.BoxSecretKey
for _, v := range k.encKeys {
out = append(out, v)
}
return out
} | [
"func",
"(",
"k",
"*",
"Keyring",
")",
"GetAllBoxSecretKeys",
"(",
")",
"[",
"]",
"saltpack",
".",
"BoxSecretKey",
"{",
"var",
"out",
"[",
"]",
"saltpack",
".",
"BoxSecretKey",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"k",
".",
"encKeys",
"{",
"out",
"=",
"append",
"(",
"out",
",",
"v",
")",
"\n",
"}",
"\n",
"return",
"out",
"\n",
"}"
] | // GetAllBoxSecretKeys returns all secret Box keys in the keyring. | [
"GetAllBoxSecretKeys",
"returns",
"all",
"secret",
"Box",
"keys",
"in",
"the",
"keyring",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/basic/key.go#L221-L227 |
1,447 | keybase/saltpack | basic/key.go | Sign | func (k SigningSecretKey) Sign(msg []byte) (ret []byte, err error) {
return ed25519.Sign(k.sec[:], msg), nil
} | go | func (k SigningSecretKey) Sign(msg []byte) (ret []byte, err error) {
return ed25519.Sign(k.sec[:], msg), nil
} | [
"func",
"(",
"k",
"SigningSecretKey",
")",
"Sign",
"(",
"msg",
"[",
"]",
"byte",
")",
"(",
"ret",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"return",
"ed25519",
".",
"Sign",
"(",
"k",
".",
"sec",
"[",
":",
"]",
",",
"msg",
")",
",",
"nil",
"\n",
"}"
] | // Sign runs the NaCl signature scheme on the input message, returning
// a signature. | [
"Sign",
"runs",
"the",
"NaCl",
"signature",
"scheme",
"on",
"the",
"input",
"message",
"returning",
"a",
"signature",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/basic/key.go#L253-L255 |
1,448 | keybase/saltpack | basic/key.go | GetRawPublicKey | func (k SigningSecretKey) GetRawPublicKey() *[ed25519.PublicKeySize]byte {
return (*[ed25519.PublicKeySize]byte)(&k.pub)
} | go | func (k SigningSecretKey) GetRawPublicKey() *[ed25519.PublicKeySize]byte {
return (*[ed25519.PublicKeySize]byte)(&k.pub)
} | [
"func",
"(",
"k",
"SigningSecretKey",
")",
"GetRawPublicKey",
"(",
")",
"*",
"[",
"ed25519",
".",
"PublicKeySize",
"]",
"byte",
"{",
"return",
"(",
"*",
"[",
"ed25519",
".",
"PublicKeySize",
"]",
"byte",
")",
"(",
"&",
"k",
".",
"pub",
")",
"\n",
"}"
] | // GetRawPublicKey returns the raw public key that corresponds to this secret key. | [
"GetRawPublicKey",
"returns",
"the",
"raw",
"public",
"key",
"that",
"corresponds",
"to",
"this",
"secret",
"key",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/basic/key.go#L272-L274 |
1,449 | keybase/saltpack | basic/key.go | GetRawSecretKey | func (k SigningSecretKey) GetRawSecretKey() *[ed25519.PrivateKeySize]byte {
return (*[ed25519.PrivateKeySize]byte)(&k.sec)
} | go | func (k SigningSecretKey) GetRawSecretKey() *[ed25519.PrivateKeySize]byte {
return (*[ed25519.PrivateKeySize]byte)(&k.sec)
} | [
"func",
"(",
"k",
"SigningSecretKey",
")",
"GetRawSecretKey",
"(",
")",
"*",
"[",
"ed25519",
".",
"PrivateKeySize",
"]",
"byte",
"{",
"return",
"(",
"*",
"[",
"ed25519",
".",
"PrivateKeySize",
"]",
"byte",
")",
"(",
"&",
"k",
".",
"sec",
")",
"\n",
"}"
] | // GetRawSecretKey returns the raw secret key. | [
"GetRawSecretKey",
"returns",
"the",
"raw",
"secret",
"key",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/basic/key.go#L277-L279 |
1,450 | keybase/saltpack | basic/key.go | NewSigningSecretKey | func NewSigningSecretKey(pub *[ed25519.PublicKeySize]byte, sec *[ed25519.PrivateKeySize]byte) SigningSecretKey {
return SigningSecretKey{
sec: rawSigningSecretKey(*sec),
pub: SigningPublicKey(*pub),
}
} | go | func NewSigningSecretKey(pub *[ed25519.PublicKeySize]byte, sec *[ed25519.PrivateKeySize]byte) SigningSecretKey {
return SigningSecretKey{
sec: rawSigningSecretKey(*sec),
pub: SigningPublicKey(*pub),
}
} | [
"func",
"NewSigningSecretKey",
"(",
"pub",
"*",
"[",
"ed25519",
".",
"PublicKeySize",
"]",
"byte",
",",
"sec",
"*",
"[",
"ed25519",
".",
"PrivateKeySize",
"]",
"byte",
")",
"SigningSecretKey",
"{",
"return",
"SigningSecretKey",
"{",
"sec",
":",
"rawSigningSecretKey",
"(",
"*",
"sec",
")",
",",
"pub",
":",
"SigningPublicKey",
"(",
"*",
"pub",
")",
",",
"}",
"\n",
"}"
] | // NewSigningSecretKey creates a new basic signing key from byte arrays. | [
"NewSigningSecretKey",
"creates",
"a",
"new",
"basic",
"signing",
"key",
"from",
"byte",
"arrays",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/basic/key.go#L294-L299 |
1,451 | keybase/saltpack | verify.go | NewVerifyStream | func NewVerifyStream(versionValidator VersionValidator, r io.Reader, keyring SigKeyring) (skey SigningPublicKey, vs io.Reader, err error) {
s, err := newVerifyStream(versionValidator, r, MessageTypeAttachedSignature)
if err != nil {
return nil, nil, err
}
skey = keyring.LookupSigningPublicKey(s.header.SenderPublic)
if skey == nil {
return nil, nil, ErrNoSenderKey
}
s.publicKey = skey
return skey, newChunkReader(s), nil
} | go | func NewVerifyStream(versionValidator VersionValidator, r io.Reader, keyring SigKeyring) (skey SigningPublicKey, vs io.Reader, err error) {
s, err := newVerifyStream(versionValidator, r, MessageTypeAttachedSignature)
if err != nil {
return nil, nil, err
}
skey = keyring.LookupSigningPublicKey(s.header.SenderPublic)
if skey == nil {
return nil, nil, ErrNoSenderKey
}
s.publicKey = skey
return skey, newChunkReader(s), nil
} | [
"func",
"NewVerifyStream",
"(",
"versionValidator",
"VersionValidator",
",",
"r",
"io",
".",
"Reader",
",",
"keyring",
"SigKeyring",
")",
"(",
"skey",
"SigningPublicKey",
",",
"vs",
"io",
".",
"Reader",
",",
"err",
"error",
")",
"{",
"s",
",",
"err",
":=",
"newVerifyStream",
"(",
"versionValidator",
",",
"r",
",",
"MessageTypeAttachedSignature",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"skey",
"=",
"keyring",
".",
"LookupSigningPublicKey",
"(",
"s",
".",
"header",
".",
"SenderPublic",
")",
"\n",
"if",
"skey",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"ErrNoSenderKey",
"\n",
"}",
"\n",
"s",
".",
"publicKey",
"=",
"skey",
"\n",
"return",
"skey",
",",
"newChunkReader",
"(",
"s",
")",
",",
"nil",
"\n",
"}"
] | // NewVerifyStream creates a stream that consumes data from reader
// r. It returns the signer's public key and a reader that only
// contains verified data. If the signer's key is not in keyring,
// it will return an error. | [
"NewVerifyStream",
"creates",
"a",
"stream",
"that",
"consumes",
"data",
"from",
"reader",
"r",
".",
"It",
"returns",
"the",
"signer",
"s",
"public",
"key",
"and",
"a",
"reader",
"that",
"only",
"contains",
"verified",
"data",
".",
"If",
"the",
"signer",
"s",
"key",
"is",
"not",
"in",
"keyring",
"it",
"will",
"return",
"an",
"error",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/verify.go#L17-L28 |
1,452 | keybase/saltpack | verify.go | Verify | func Verify(versionValidator VersionValidator, signedMsg []byte, keyring SigKeyring) (skey SigningPublicKey, verifiedMsg []byte, err error) {
skey, stream, err := NewVerifyStream(versionValidator, bytes.NewReader(signedMsg), keyring)
if err != nil {
return nil, nil, err
}
verifiedMsg, err = ioutil.ReadAll(stream)
if err != nil {
return nil, nil, err
}
return skey, verifiedMsg, nil
} | go | func Verify(versionValidator VersionValidator, signedMsg []byte, keyring SigKeyring) (skey SigningPublicKey, verifiedMsg []byte, err error) {
skey, stream, err := NewVerifyStream(versionValidator, bytes.NewReader(signedMsg), keyring)
if err != nil {
return nil, nil, err
}
verifiedMsg, err = ioutil.ReadAll(stream)
if err != nil {
return nil, nil, err
}
return skey, verifiedMsg, nil
} | [
"func",
"Verify",
"(",
"versionValidator",
"VersionValidator",
",",
"signedMsg",
"[",
"]",
"byte",
",",
"keyring",
"SigKeyring",
")",
"(",
"skey",
"SigningPublicKey",
",",
"verifiedMsg",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"skey",
",",
"stream",
",",
"err",
":=",
"NewVerifyStream",
"(",
"versionValidator",
",",
"bytes",
".",
"NewReader",
"(",
"signedMsg",
")",
",",
"keyring",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"verifiedMsg",
",",
"err",
"=",
"ioutil",
".",
"ReadAll",
"(",
"stream",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"skey",
",",
"verifiedMsg",
",",
"nil",
"\n",
"}"
] | // Verify checks the signature in signedMsg. It returns the
// signer's public key and a verified message. | [
"Verify",
"checks",
"the",
"signature",
"in",
"signedMsg",
".",
"It",
"returns",
"the",
"signer",
"s",
"public",
"key",
"and",
"a",
"verified",
"message",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/verify.go#L32-L43 |
1,453 | keybase/saltpack | verify.go | VerifyDetachedReader | func VerifyDetachedReader(versionValidator VersionValidator, message io.Reader, signature []byte, keyring SigKeyring) (skey SigningPublicKey, err error) {
inputBuffer := bytes.NewBuffer(signature)
// Use a verifyStream to parse the header.
s, err := newVerifyStream(versionValidator, inputBuffer, MessageTypeDetachedSignature)
if err != nil {
return nil, err
}
// Reach inside the verifyStream to parse the signature bytes.
var naclSignature []byte
_, err = s.mps.Read(&naclSignature)
if err != nil {
return nil, err
}
// Get the public key.
skey = keyring.LookupSigningPublicKey(s.header.SenderPublic)
if skey == nil {
return nil, ErrNoSenderKey
}
// Compute the signed text hash, without requiring us to copy the whole
// signed text into memory at once.
hasher := sha512.New()
hasher.Write(s.headerHash[:])
if _, err := io.Copy(hasher, message); err != nil {
return nil, err
}
if err := skey.Verify(detachedSignatureInputFromHash(hasher.Sum(nil)), naclSignature); err != nil {
return nil, err
}
return skey, nil
} | go | func VerifyDetachedReader(versionValidator VersionValidator, message io.Reader, signature []byte, keyring SigKeyring) (skey SigningPublicKey, err error) {
inputBuffer := bytes.NewBuffer(signature)
// Use a verifyStream to parse the header.
s, err := newVerifyStream(versionValidator, inputBuffer, MessageTypeDetachedSignature)
if err != nil {
return nil, err
}
// Reach inside the verifyStream to parse the signature bytes.
var naclSignature []byte
_, err = s.mps.Read(&naclSignature)
if err != nil {
return nil, err
}
// Get the public key.
skey = keyring.LookupSigningPublicKey(s.header.SenderPublic)
if skey == nil {
return nil, ErrNoSenderKey
}
// Compute the signed text hash, without requiring us to copy the whole
// signed text into memory at once.
hasher := sha512.New()
hasher.Write(s.headerHash[:])
if _, err := io.Copy(hasher, message); err != nil {
return nil, err
}
if err := skey.Verify(detachedSignatureInputFromHash(hasher.Sum(nil)), naclSignature); err != nil {
return nil, err
}
return skey, nil
} | [
"func",
"VerifyDetachedReader",
"(",
"versionValidator",
"VersionValidator",
",",
"message",
"io",
".",
"Reader",
",",
"signature",
"[",
"]",
"byte",
",",
"keyring",
"SigKeyring",
")",
"(",
"skey",
"SigningPublicKey",
",",
"err",
"error",
")",
"{",
"inputBuffer",
":=",
"bytes",
".",
"NewBuffer",
"(",
"signature",
")",
"\n\n",
"// Use a verifyStream to parse the header.",
"s",
",",
"err",
":=",
"newVerifyStream",
"(",
"versionValidator",
",",
"inputBuffer",
",",
"MessageTypeDetachedSignature",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Reach inside the verifyStream to parse the signature bytes.",
"var",
"naclSignature",
"[",
"]",
"byte",
"\n",
"_",
",",
"err",
"=",
"s",
".",
"mps",
".",
"Read",
"(",
"&",
"naclSignature",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Get the public key.",
"skey",
"=",
"keyring",
".",
"LookupSigningPublicKey",
"(",
"s",
".",
"header",
".",
"SenderPublic",
")",
"\n",
"if",
"skey",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrNoSenderKey",
"\n",
"}",
"\n\n",
"// Compute the signed text hash, without requiring us to copy the whole",
"// signed text into memory at once.",
"hasher",
":=",
"sha512",
".",
"New",
"(",
")",
"\n",
"hasher",
".",
"Write",
"(",
"s",
".",
"headerHash",
"[",
":",
"]",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"Copy",
"(",
"hasher",
",",
"message",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"skey",
".",
"Verify",
"(",
"detachedSignatureInputFromHash",
"(",
"hasher",
".",
"Sum",
"(",
"nil",
")",
")",
",",
"naclSignature",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"skey",
",",
"nil",
"\n",
"}"
] | // VerifyDetachedReader verifies that signature is a valid signature for
// entire message read from message Reader, and that the public key for
// the signer is in keyring. It returns the signer's public key. | [
"VerifyDetachedReader",
"verifies",
"that",
"signature",
"is",
"a",
"valid",
"signature",
"for",
"entire",
"message",
"read",
"from",
"message",
"Reader",
"and",
"that",
"the",
"public",
"key",
"for",
"the",
"signer",
"is",
"in",
"keyring",
".",
"It",
"returns",
"the",
"signer",
"s",
"public",
"key",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/verify.go#L48-L83 |
1,454 | keybase/saltpack | verify.go | VerifyDetached | func VerifyDetached(versionValidator VersionValidator, message, signature []byte, keyring SigKeyring) (skey SigningPublicKey, err error) {
return VerifyDetachedReader(versionValidator, bytes.NewReader(message), signature, keyring)
} | go | func VerifyDetached(versionValidator VersionValidator, message, signature []byte, keyring SigKeyring) (skey SigningPublicKey, err error) {
return VerifyDetachedReader(versionValidator, bytes.NewReader(message), signature, keyring)
} | [
"func",
"VerifyDetached",
"(",
"versionValidator",
"VersionValidator",
",",
"message",
",",
"signature",
"[",
"]",
"byte",
",",
"keyring",
"SigKeyring",
")",
"(",
"skey",
"SigningPublicKey",
",",
"err",
"error",
")",
"{",
"return",
"VerifyDetachedReader",
"(",
"versionValidator",
",",
"bytes",
".",
"NewReader",
"(",
"message",
")",
",",
"signature",
",",
"keyring",
")",
"\n",
"}"
] | // VerifyDetached verifies that signature is a valid signature for
// message, and that the public key for the signer is in keyring.
// It returns the signer's public key. | [
"VerifyDetached",
"verifies",
"that",
"signature",
"is",
"a",
"valid",
"signature",
"for",
"message",
"and",
"that",
"the",
"public",
"key",
"for",
"the",
"signer",
"is",
"in",
"keyring",
".",
"It",
"returns",
"the",
"signer",
"s",
"public",
"key",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/verify.go#L88-L90 |
1,455 | keybase/saltpack | armor62_sign.go | NewSignArmor62Stream | func NewSignArmor62Stream(version Version, signedtext io.Writer, signer SigningSecretKey, brand string) (stream io.WriteCloser, err error) {
enc, err := NewArmor62EncoderStream(signedtext, MessageTypeAttachedSignature, brand)
if err != nil {
return nil, err
}
out, err := NewSignStream(version, enc, signer)
if err != nil {
return nil, err
}
return closeForwarder([]io.WriteCloser{out, enc}), nil
} | go | func NewSignArmor62Stream(version Version, signedtext io.Writer, signer SigningSecretKey, brand string) (stream io.WriteCloser, err error) {
enc, err := NewArmor62EncoderStream(signedtext, MessageTypeAttachedSignature, brand)
if err != nil {
return nil, err
}
out, err := NewSignStream(version, enc, signer)
if err != nil {
return nil, err
}
return closeForwarder([]io.WriteCloser{out, enc}), nil
} | [
"func",
"NewSignArmor62Stream",
"(",
"version",
"Version",
",",
"signedtext",
"io",
".",
"Writer",
",",
"signer",
"SigningSecretKey",
",",
"brand",
"string",
")",
"(",
"stream",
"io",
".",
"WriteCloser",
",",
"err",
"error",
")",
"{",
"enc",
",",
"err",
":=",
"NewArmor62EncoderStream",
"(",
"signedtext",
",",
"MessageTypeAttachedSignature",
",",
"brand",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"out",
",",
"err",
":=",
"NewSignStream",
"(",
"version",
",",
"enc",
",",
"signer",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"closeForwarder",
"(",
"[",
"]",
"io",
".",
"WriteCloser",
"{",
"out",
",",
"enc",
"}",
")",
",",
"nil",
"\n",
"}"
] | // NewSignArmor62Stream creates a stream that consumes plaintext data.
// It will write out signed data to the io.Writer passed in as
// signedtext. The `brand` is optional, and allows you to specify
// your "white label" brand to this signature. NewSignArmor62Stream only
// generates attached signatures.
//
// The signed data is armored with the recommended armor62-style
// format. | [
"NewSignArmor62Stream",
"creates",
"a",
"stream",
"that",
"consumes",
"plaintext",
"data",
".",
"It",
"will",
"write",
"out",
"signed",
"data",
"to",
"the",
"io",
".",
"Writer",
"passed",
"in",
"as",
"signedtext",
".",
"The",
"brand",
"is",
"optional",
"and",
"allows",
"you",
"to",
"specify",
"your",
"white",
"label",
"brand",
"to",
"this",
"signature",
".",
"NewSignArmor62Stream",
"only",
"generates",
"attached",
"signatures",
".",
"The",
"signed",
"data",
"is",
"armored",
"with",
"the",
"recommended",
"armor62",
"-",
"style",
"format",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/armor62_sign.go#L22-L32 |
1,456 | keybase/saltpack | armor62_sign.go | SignArmor62 | func SignArmor62(version Version, plaintext []byte, signer SigningSecretKey, brand string) (string, error) {
buf, err := signToStream(version, plaintext, signer, applyBrand(NewSignArmor62Stream, brand))
if err != nil {
return "", err
}
return buf.String(), nil
} | go | func SignArmor62(version Version, plaintext []byte, signer SigningSecretKey, brand string) (string, error) {
buf, err := signToStream(version, plaintext, signer, applyBrand(NewSignArmor62Stream, brand))
if err != nil {
return "", err
}
return buf.String(), nil
} | [
"func",
"SignArmor62",
"(",
"version",
"Version",
",",
"plaintext",
"[",
"]",
"byte",
",",
"signer",
"SigningSecretKey",
",",
"brand",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"buf",
",",
"err",
":=",
"signToStream",
"(",
"version",
",",
"plaintext",
",",
"signer",
",",
"applyBrand",
"(",
"NewSignArmor62Stream",
",",
"brand",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
",",
"nil",
"\n",
"}"
] | // SignArmor62 creates an attached armored signature message of plaintext from signer. | [
"SignArmor62",
"creates",
"an",
"attached",
"armored",
"signature",
"message",
"of",
"plaintext",
"from",
"signer",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/armor62_sign.go#L35-L41 |
1,457 | keybase/saltpack | armor62_sign.go | NewSignDetachedArmor62Stream | func NewSignDetachedArmor62Stream(version Version, detachedsig io.Writer, signer SigningSecretKey, brand string) (stream io.WriteCloser, err error) {
enc, err := NewArmor62EncoderStream(detachedsig, MessageTypeDetachedSignature, brand)
if err != nil {
return nil, err
}
out, err := NewSignDetachedStream(version, enc, signer)
if err != nil {
return nil, err
}
return closeForwarder([]io.WriteCloser{out, enc}), nil
} | go | func NewSignDetachedArmor62Stream(version Version, detachedsig io.Writer, signer SigningSecretKey, brand string) (stream io.WriteCloser, err error) {
enc, err := NewArmor62EncoderStream(detachedsig, MessageTypeDetachedSignature, brand)
if err != nil {
return nil, err
}
out, err := NewSignDetachedStream(version, enc, signer)
if err != nil {
return nil, err
}
return closeForwarder([]io.WriteCloser{out, enc}), nil
} | [
"func",
"NewSignDetachedArmor62Stream",
"(",
"version",
"Version",
",",
"detachedsig",
"io",
".",
"Writer",
",",
"signer",
"SigningSecretKey",
",",
"brand",
"string",
")",
"(",
"stream",
"io",
".",
"WriteCloser",
",",
"err",
"error",
")",
"{",
"enc",
",",
"err",
":=",
"NewArmor62EncoderStream",
"(",
"detachedsig",
",",
"MessageTypeDetachedSignature",
",",
"brand",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"out",
",",
"err",
":=",
"NewSignDetachedStream",
"(",
"version",
",",
"enc",
",",
"signer",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"closeForwarder",
"(",
"[",
"]",
"io",
".",
"WriteCloser",
"{",
"out",
",",
"enc",
"}",
")",
",",
"nil",
"\n\n",
"}"
] | // NewSignDetachedArmor62Stream creates a stream that consumes plaintext data.
// It will write out the detached signature to the io.Writer passed in as
// detachedsig. The `brand` is optional, and allows you to specify
// your "white label" brand to this signature.
//
// The signed data is armored with the recommended armor62-style
// NewSignDetachedArmor62Stream only generates detached signatures.
//
// The signature is armored with the recommended armor62-style
// format. | [
"NewSignDetachedArmor62Stream",
"creates",
"a",
"stream",
"that",
"consumes",
"plaintext",
"data",
".",
"It",
"will",
"write",
"out",
"the",
"detached",
"signature",
"to",
"the",
"io",
".",
"Writer",
"passed",
"in",
"as",
"detachedsig",
".",
"The",
"brand",
"is",
"optional",
"and",
"allows",
"you",
"to",
"specify",
"your",
"white",
"label",
"brand",
"to",
"this",
"signature",
".",
"The",
"signed",
"data",
"is",
"armored",
"with",
"the",
"recommended",
"armor62",
"-",
"style",
"NewSignDetachedArmor62Stream",
"only",
"generates",
"detached",
"signatures",
".",
"The",
"signature",
"is",
"armored",
"with",
"the",
"recommended",
"armor62",
"-",
"style",
"format",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/armor62_sign.go#L53-L64 |
1,458 | keybase/saltpack | armor62_sign.go | SignDetachedArmor62 | func SignDetachedArmor62(version Version, plaintext []byte, signer SigningSecretKey, brand string) (string, error) {
buf, err := signToStream(version, plaintext, signer, applyBrand(NewSignDetachedArmor62Stream, brand))
if err != nil {
return "", err
}
return buf.String(), nil
} | go | func SignDetachedArmor62(version Version, plaintext []byte, signer SigningSecretKey, brand string) (string, error) {
buf, err := signToStream(version, plaintext, signer, applyBrand(NewSignDetachedArmor62Stream, brand))
if err != nil {
return "", err
}
return buf.String(), nil
} | [
"func",
"SignDetachedArmor62",
"(",
"version",
"Version",
",",
"plaintext",
"[",
"]",
"byte",
",",
"signer",
"SigningSecretKey",
",",
"brand",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"buf",
",",
"err",
":=",
"signToStream",
"(",
"version",
",",
"plaintext",
",",
"signer",
",",
"applyBrand",
"(",
"NewSignDetachedArmor62Stream",
",",
"brand",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
",",
"nil",
"\n",
"}"
] | // SignDetachedArmor62 returns a detached armored signature of plaintext from signer. | [
"SignDetachedArmor62",
"returns",
"a",
"detached",
"armored",
"signature",
"of",
"plaintext",
"from",
"signer",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/armor62_sign.go#L67-L73 |
1,459 | keybase/saltpack | armor.go | armorSeal | func armorSeal(plaintext []byte, header string, footer string, params armorParams) (string, error) {
var buf bytes.Buffer
enc, err := newArmorEncoderStream(&buf, header, footer, params)
if err != nil {
return "", err
}
if _, err := enc.Write(plaintext); err != nil {
return "", err
}
if err := enc.Close(); err != nil {
return "", err
}
return buf.String(), nil
} | go | func armorSeal(plaintext []byte, header string, footer string, params armorParams) (string, error) {
var buf bytes.Buffer
enc, err := newArmorEncoderStream(&buf, header, footer, params)
if err != nil {
return "", err
}
if _, err := enc.Write(plaintext); err != nil {
return "", err
}
if err := enc.Close(); err != nil {
return "", err
}
return buf.String(), nil
} | [
"func",
"armorSeal",
"(",
"plaintext",
"[",
"]",
"byte",
",",
"header",
"string",
",",
"footer",
"string",
",",
"params",
"armorParams",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"enc",
",",
"err",
":=",
"newArmorEncoderStream",
"(",
"&",
"buf",
",",
"header",
",",
"footer",
",",
"params",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"enc",
".",
"Write",
"(",
"plaintext",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"enc",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
",",
"nil",
"\n",
"}"
] | // armorSeal takes an input plaintext and returns and output armor encoding
// as a string, or an error if a problem was encountered. Also provide a header
// and a footer to frame the message. | [
"armorSeal",
"takes",
"an",
"input",
"plaintext",
"and",
"returns",
"and",
"output",
"armor",
"encoding",
"as",
"a",
"string",
"or",
"an",
"error",
"if",
"a",
"problem",
"was",
"encountered",
".",
"Also",
"provide",
"a",
"header",
"and",
"a",
"footer",
"to",
"frame",
"the",
"message",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/armor.go#L118-L131 |
1,460 | keybase/saltpack | armor.go | Read | func (s *framedDecoderStream) Read(p []byte) (n int, err error) {
if s.state == fdsHeader {
err = s.loadHeader()
if err != nil {
return 0, err
}
}
if s.state == fdsBody {
n, err = s.r.Read(p)
if err == ErrPunctuated {
err = nil
s.state = fdsFooter
}
if err == io.EOF {
err = io.ErrUnexpectedEOF
}
if err != nil {
return 0, err
}
}
if s.state == fdsFooter {
s.footer, err = s.r.ReadUntilPunctuation(s.frameLim)
if err != nil {
return 0, err
}
if s.frameChecker != nil {
headerStr, err := s.toASCII(s.header)
if err != nil {
return 0, err
}
footerStr, err := s.toASCII(s.footer)
if err != nil {
return 0, err
}
if _, err = s.frameChecker(headerStr, footerStr); err != nil {
return 0, err
}
}
s.state = fdsEndOfStream
}
if s.state == fdsEndOfStream {
err = s.consumeUntilEOF()
if err == io.EOF && n > 0 {
err = nil
}
}
return n, err
} | go | func (s *framedDecoderStream) Read(p []byte) (n int, err error) {
if s.state == fdsHeader {
err = s.loadHeader()
if err != nil {
return 0, err
}
}
if s.state == fdsBody {
n, err = s.r.Read(p)
if err == ErrPunctuated {
err = nil
s.state = fdsFooter
}
if err == io.EOF {
err = io.ErrUnexpectedEOF
}
if err != nil {
return 0, err
}
}
if s.state == fdsFooter {
s.footer, err = s.r.ReadUntilPunctuation(s.frameLim)
if err != nil {
return 0, err
}
if s.frameChecker != nil {
headerStr, err := s.toASCII(s.header)
if err != nil {
return 0, err
}
footerStr, err := s.toASCII(s.footer)
if err != nil {
return 0, err
}
if _, err = s.frameChecker(headerStr, footerStr); err != nil {
return 0, err
}
}
s.state = fdsEndOfStream
}
if s.state == fdsEndOfStream {
err = s.consumeUntilEOF()
if err == io.EOF && n > 0 {
err = nil
}
}
return n, err
} | [
"func",
"(",
"s",
"*",
"framedDecoderStream",
")",
"Read",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"if",
"s",
".",
"state",
"==",
"fdsHeader",
"{",
"err",
"=",
"s",
".",
"loadHeader",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"s",
".",
"state",
"==",
"fdsBody",
"{",
"n",
",",
"err",
"=",
"s",
".",
"r",
".",
"Read",
"(",
"p",
")",
"\n",
"if",
"err",
"==",
"ErrPunctuated",
"{",
"err",
"=",
"nil",
"\n",
"s",
".",
"state",
"=",
"fdsFooter",
"\n",
"}",
"\n",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"err",
"=",
"io",
".",
"ErrUnexpectedEOF",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"s",
".",
"state",
"==",
"fdsFooter",
"{",
"s",
".",
"footer",
",",
"err",
"=",
"s",
".",
"r",
".",
"ReadUntilPunctuation",
"(",
"s",
".",
"frameLim",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"if",
"s",
".",
"frameChecker",
"!=",
"nil",
"{",
"headerStr",
",",
"err",
":=",
"s",
".",
"toASCII",
"(",
"s",
".",
"header",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"footerStr",
",",
"err",
":=",
"s",
".",
"toASCII",
"(",
"s",
".",
"footer",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
"=",
"s",
".",
"frameChecker",
"(",
"headerStr",
",",
"footerStr",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"s",
".",
"state",
"=",
"fdsEndOfStream",
"\n",
"}",
"\n\n",
"if",
"s",
".",
"state",
"==",
"fdsEndOfStream",
"{",
"err",
"=",
"s",
".",
"consumeUntilEOF",
"(",
")",
"\n",
"if",
"err",
"==",
"io",
".",
"EOF",
"&&",
"n",
">",
"0",
"{",
"err",
"=",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"n",
",",
"err",
"\n",
"}"
] | // Read from a framedDeecoderStream. The frame is the "BEGIN FOO." block
// at the beginning, and the "END FOO." block at the end. | [
"Read",
"from",
"a",
"framedDeecoderStream",
".",
"The",
"frame",
"is",
"the",
"BEGIN",
"FOO",
".",
"block",
"at",
"the",
"beginning",
"and",
"the",
"END",
"FOO",
".",
"block",
"at",
"the",
"end",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/armor.go#L198-L250 |
1,461 | keybase/saltpack | armor.go | consumeUntilEOF | func (s *framedDecoderStream) consumeUntilEOF() error {
var buf [4096]byte
for {
n, err := s.r.Read(buf[:])
if err != nil {
return err
}
if n == 0 {
return io.EOF
}
if !s.isValidByteSequence(buf[0:n]) {
return ErrTrailingGarbage
}
}
} | go | func (s *framedDecoderStream) consumeUntilEOF() error {
var buf [4096]byte
for {
n, err := s.r.Read(buf[:])
if err != nil {
return err
}
if n == 0 {
return io.EOF
}
if !s.isValidByteSequence(buf[0:n]) {
return ErrTrailingGarbage
}
}
} | [
"func",
"(",
"s",
"*",
"framedDecoderStream",
")",
"consumeUntilEOF",
"(",
")",
"error",
"{",
"var",
"buf",
"[",
"4096",
"]",
"byte",
"\n",
"for",
"{",
"n",
",",
"err",
":=",
"s",
".",
"r",
".",
"Read",
"(",
"buf",
"[",
":",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"n",
"==",
"0",
"{",
"return",
"io",
".",
"EOF",
"\n",
"}",
"\n",
"if",
"!",
"s",
".",
"isValidByteSequence",
"(",
"buf",
"[",
"0",
":",
"n",
"]",
")",
"{",
"return",
"ErrTrailingGarbage",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // consume the stream until we hit an EOF. For all data we consume, make
// sure that it's a valid byte as far as our underlying decoder is concerned.
// We might considering clamping down here on the number of characters we're willing
// to accept after the message is over. But for now, we're quite liberal. | [
"consume",
"the",
"stream",
"until",
"we",
"hit",
"an",
"EOF",
".",
"For",
"all",
"data",
"we",
"consume",
"make",
"sure",
"that",
"it",
"s",
"a",
"valid",
"byte",
"as",
"far",
"as",
"our",
"underlying",
"decoder",
"is",
"concerned",
".",
"We",
"might",
"considering",
"clamping",
"down",
"here",
"on",
"the",
"number",
"of",
"characters",
"we",
"re",
"willing",
"to",
"accept",
"after",
"the",
"message",
"is",
"over",
".",
"But",
"for",
"now",
"we",
"re",
"quite",
"liberal",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/armor.go#L256-L270 |
1,462 | keybase/saltpack | armor.go | isValidByteSequence | func (s *framedDecoderStream) isValidByteSequence(p []byte) bool {
for _, b := range p {
if !s.params.Encoding.IsValidByte(b) {
return false
}
}
return true
} | go | func (s *framedDecoderStream) isValidByteSequence(p []byte) bool {
for _, b := range p {
if !s.params.Encoding.IsValidByte(b) {
return false
}
}
return true
} | [
"func",
"(",
"s",
"*",
"framedDecoderStream",
")",
"isValidByteSequence",
"(",
"p",
"[",
"]",
"byte",
")",
"bool",
"{",
"for",
"_",
",",
"b",
":=",
"range",
"p",
"{",
"if",
"!",
"s",
".",
"params",
".",
"Encoding",
".",
"IsValidByte",
"(",
"b",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // isValidByteSequence checks if the byte sequence is valid as far as our
// underlying encoder is concerned. | [
"isValidByteSequence",
"checks",
"if",
"the",
"byte",
"sequence",
"is",
"valid",
"as",
"far",
"as",
"our",
"underlying",
"encoder",
"is",
"concerned",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/armor.go#L274-L281 |
1,463 | keybase/saltpack | armor.go | armorOpen | func armorOpen(msg string, params armorParams, headerChecker HeaderChecker, frameChecker FrameChecker) (body []byte, brand string, header string, footer string, err error) {
var dec io.Reader
var frame Frame
buf := bytes.NewBufferString(msg)
dec, frame, err = newArmorDecoderStream(buf, params, headerChecker, frameChecker)
if err != nil {
return
}
body, err = ioutil.ReadAll(dec)
if err != nil {
return
}
if header, err = frame.GetHeader(); err != nil {
return
}
if footer, err = frame.GetFooter(); err != nil {
return
}
if brand, err = frame.GetBrand(); err != nil {
return
}
return body, brand, header, footer, nil
} | go | func armorOpen(msg string, params armorParams, headerChecker HeaderChecker, frameChecker FrameChecker) (body []byte, brand string, header string, footer string, err error) {
var dec io.Reader
var frame Frame
buf := bytes.NewBufferString(msg)
dec, frame, err = newArmorDecoderStream(buf, params, headerChecker, frameChecker)
if err != nil {
return
}
body, err = ioutil.ReadAll(dec)
if err != nil {
return
}
if header, err = frame.GetHeader(); err != nil {
return
}
if footer, err = frame.GetFooter(); err != nil {
return
}
if brand, err = frame.GetBrand(); err != nil {
return
}
return body, brand, header, footer, nil
} | [
"func",
"armorOpen",
"(",
"msg",
"string",
",",
"params",
"armorParams",
",",
"headerChecker",
"HeaderChecker",
",",
"frameChecker",
"FrameChecker",
")",
"(",
"body",
"[",
"]",
"byte",
",",
"brand",
"string",
",",
"header",
"string",
",",
"footer",
"string",
",",
"err",
"error",
")",
"{",
"var",
"dec",
"io",
".",
"Reader",
"\n",
"var",
"frame",
"Frame",
"\n",
"buf",
":=",
"bytes",
".",
"NewBufferString",
"(",
"msg",
")",
"\n",
"dec",
",",
"frame",
",",
"err",
"=",
"newArmorDecoderStream",
"(",
"buf",
",",
"params",
",",
"headerChecker",
",",
"frameChecker",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"body",
",",
"err",
"=",
"ioutil",
".",
"ReadAll",
"(",
"dec",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"header",
",",
"err",
"=",
"frame",
".",
"GetHeader",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"footer",
",",
"err",
"=",
"frame",
".",
"GetFooter",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"brand",
",",
"err",
"=",
"frame",
".",
"GetBrand",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"return",
"body",
",",
"brand",
",",
"header",
",",
"footer",
",",
"nil",
"\n",
"}"
] | // armorOpen runs armor stream decoding, but on a string, and it outputs a string. | [
"armorOpen",
"runs",
"armor",
"stream",
"decoding",
"but",
"on",
"a",
"string",
"and",
"it",
"outputs",
"a",
"string",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/armor.go#L326-L348 |
1,464 | keybase/saltpack | punctuated_reader.go | Read | func (p *punctuatedReader) Read(out []byte) (n int, err error) {
// First deal with the case that we had a "short copy" to our target buffer
// in a previous call of the read function.
if len(p.thisSegment) > 0 {
n = copy(out, p.thisSegment)
p.thisSegment = p.thisSegment[n:]
if len(p.thisSegment) == 0 {
err = p.errThisSegment
p.errThisSegment = nil
}
return n, err
}
// In this case we have no previous short copy, so now we deal with
// two cases --- we had, from a previous iteration, some stuff after the
// punctuation. Or we need to read again.
var src []byte
usedBuffer := false
if len(p.nextSegment) > 0 {
src = p.nextSegment
usedBuffer = true
p.nextSegment = nil
} else {
n, err = p.r.Read(out)
if err != nil {
return n, err
}
src = out[0:n]
}
// Now look for punctuation. If we find it, we need to keep the remaining
// data in the buffer (to the right of the punctuation mark) for the next
// time through the loop. Note that that new buffer can itself have subsequent
// punctuation, so we'll have to perform the check again here.
foundPunc := false
if i := bytes.Index(src, p.punctuation[:]); i >= 0 {
p.nextSegment = src[(i + 1):]
src = src[0:i]
n = len(src)
foundPunc = true
}
// If we used a buffer, copy into the output buffer, and potentially deal
// with a "short copy" situation in which we couldn't fit all of the data
// into the given buffer.
if usedBuffer {
n = copy(out, src)
p.thisSegment = src[n:]
}
// If we found punctuation, we have to set an error accordingly. However,
// in the "short copy" situation just above, we can't return the error just
// yet, we need to do so when that buffer is drained.
if foundPunc {
if len(p.thisSegment) > 0 {
p.errThisSegment = ErrPunctuated
} else {
err = ErrPunctuated
}
}
return n, err
} | go | func (p *punctuatedReader) Read(out []byte) (n int, err error) {
// First deal with the case that we had a "short copy" to our target buffer
// in a previous call of the read function.
if len(p.thisSegment) > 0 {
n = copy(out, p.thisSegment)
p.thisSegment = p.thisSegment[n:]
if len(p.thisSegment) == 0 {
err = p.errThisSegment
p.errThisSegment = nil
}
return n, err
}
// In this case we have no previous short copy, so now we deal with
// two cases --- we had, from a previous iteration, some stuff after the
// punctuation. Or we need to read again.
var src []byte
usedBuffer := false
if len(p.nextSegment) > 0 {
src = p.nextSegment
usedBuffer = true
p.nextSegment = nil
} else {
n, err = p.r.Read(out)
if err != nil {
return n, err
}
src = out[0:n]
}
// Now look for punctuation. If we find it, we need to keep the remaining
// data in the buffer (to the right of the punctuation mark) for the next
// time through the loop. Note that that new buffer can itself have subsequent
// punctuation, so we'll have to perform the check again here.
foundPunc := false
if i := bytes.Index(src, p.punctuation[:]); i >= 0 {
p.nextSegment = src[(i + 1):]
src = src[0:i]
n = len(src)
foundPunc = true
}
// If we used a buffer, copy into the output buffer, and potentially deal
// with a "short copy" situation in which we couldn't fit all of the data
// into the given buffer.
if usedBuffer {
n = copy(out, src)
p.thisSegment = src[n:]
}
// If we found punctuation, we have to set an error accordingly. However,
// in the "short copy" situation just above, we can't return the error just
// yet, we need to do so when that buffer is drained.
if foundPunc {
if len(p.thisSegment) > 0 {
p.errThisSegment = ErrPunctuated
} else {
err = ErrPunctuated
}
}
return n, err
} | [
"func",
"(",
"p",
"*",
"punctuatedReader",
")",
"Read",
"(",
"out",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"// First deal with the case that we had a \"short copy\" to our target buffer",
"// in a previous call of the read function.",
"if",
"len",
"(",
"p",
".",
"thisSegment",
")",
">",
"0",
"{",
"n",
"=",
"copy",
"(",
"out",
",",
"p",
".",
"thisSegment",
")",
"\n",
"p",
".",
"thisSegment",
"=",
"p",
".",
"thisSegment",
"[",
"n",
":",
"]",
"\n",
"if",
"len",
"(",
"p",
".",
"thisSegment",
")",
"==",
"0",
"{",
"err",
"=",
"p",
".",
"errThisSegment",
"\n",
"p",
".",
"errThisSegment",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"n",
",",
"err",
"\n",
"}",
"\n\n",
"// In this case we have no previous short copy, so now we deal with",
"// two cases --- we had, from a previous iteration, some stuff after the",
"// punctuation. Or we need to read again.",
"var",
"src",
"[",
"]",
"byte",
"\n",
"usedBuffer",
":=",
"false",
"\n",
"if",
"len",
"(",
"p",
".",
"nextSegment",
")",
">",
"0",
"{",
"src",
"=",
"p",
".",
"nextSegment",
"\n",
"usedBuffer",
"=",
"true",
"\n",
"p",
".",
"nextSegment",
"=",
"nil",
"\n",
"}",
"else",
"{",
"n",
",",
"err",
"=",
"p",
".",
"r",
".",
"Read",
"(",
"out",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"n",
",",
"err",
"\n",
"}",
"\n",
"src",
"=",
"out",
"[",
"0",
":",
"n",
"]",
"\n",
"}",
"\n\n",
"// Now look for punctuation. If we find it, we need to keep the remaining",
"// data in the buffer (to the right of the punctuation mark) for the next",
"// time through the loop. Note that that new buffer can itself have subsequent",
"// punctuation, so we'll have to perform the check again here.",
"foundPunc",
":=",
"false",
"\n",
"if",
"i",
":=",
"bytes",
".",
"Index",
"(",
"src",
",",
"p",
".",
"punctuation",
"[",
":",
"]",
")",
";",
"i",
">=",
"0",
"{",
"p",
".",
"nextSegment",
"=",
"src",
"[",
"(",
"i",
"+",
"1",
")",
":",
"]",
"\n",
"src",
"=",
"src",
"[",
"0",
":",
"i",
"]",
"\n",
"n",
"=",
"len",
"(",
"src",
")",
"\n",
"foundPunc",
"=",
"true",
"\n",
"}",
"\n\n",
"// If we used a buffer, copy into the output buffer, and potentially deal",
"// with a \"short copy\" situation in which we couldn't fit all of the data",
"// into the given buffer.",
"if",
"usedBuffer",
"{",
"n",
"=",
"copy",
"(",
"out",
",",
"src",
")",
"\n",
"p",
".",
"thisSegment",
"=",
"src",
"[",
"n",
":",
"]",
"\n",
"}",
"\n\n",
"// If we found punctuation, we have to set an error accordingly. However,",
"// in the \"short copy\" situation just above, we can't return the error just",
"// yet, we need to do so when that buffer is drained.",
"if",
"foundPunc",
"{",
"if",
"len",
"(",
"p",
".",
"thisSegment",
")",
">",
"0",
"{",
"p",
".",
"errThisSegment",
"=",
"ErrPunctuated",
"\n",
"}",
"else",
"{",
"err",
"=",
"ErrPunctuated",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"n",
",",
"err",
"\n",
"}"
] | // Read from the punctuatedReader, potentially returning an `ErrPunctuation`
// if a punctuation character was found. | [
"Read",
"from",
"the",
"punctuatedReader",
"potentially",
"returning",
"an",
"ErrPunctuation",
"if",
"a",
"punctuation",
"character",
"was",
"found",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/punctuated_reader.go#L35-L98 |
1,465 | keybase/saltpack | punctuated_reader.go | ReadUntilPunctuation | func (p *punctuatedReader) ReadUntilPunctuation(lim int) (res []byte, err error) {
for {
var n int
n, err = p.Read(p.buf[:])
if err == ErrPunctuated || err == nil {
res = append(res, p.buf[0:n]...)
if err == ErrPunctuated {
err = nil
return res, err
}
if len(res) >= lim {
return nil, ErrOverflow
}
} else if err != nil {
if err == io.EOF {
err = io.ErrUnexpectedEOF
}
return nil, err
} else if n == 0 {
return nil, io.ErrUnexpectedEOF
}
}
} | go | func (p *punctuatedReader) ReadUntilPunctuation(lim int) (res []byte, err error) {
for {
var n int
n, err = p.Read(p.buf[:])
if err == ErrPunctuated || err == nil {
res = append(res, p.buf[0:n]...)
if err == ErrPunctuated {
err = nil
return res, err
}
if len(res) >= lim {
return nil, ErrOverflow
}
} else if err != nil {
if err == io.EOF {
err = io.ErrUnexpectedEOF
}
return nil, err
} else if n == 0 {
return nil, io.ErrUnexpectedEOF
}
}
} | [
"func",
"(",
"p",
"*",
"punctuatedReader",
")",
"ReadUntilPunctuation",
"(",
"lim",
"int",
")",
"(",
"res",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"for",
"{",
"var",
"n",
"int",
"\n",
"n",
",",
"err",
"=",
"p",
".",
"Read",
"(",
"p",
".",
"buf",
"[",
":",
"]",
")",
"\n",
"if",
"err",
"==",
"ErrPunctuated",
"||",
"err",
"==",
"nil",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"p",
".",
"buf",
"[",
"0",
":",
"n",
"]",
"...",
")",
"\n",
"if",
"err",
"==",
"ErrPunctuated",
"{",
"err",
"=",
"nil",
"\n",
"return",
"res",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"res",
")",
">=",
"lim",
"{",
"return",
"nil",
",",
"ErrOverflow",
"\n",
"}",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"err",
"=",
"io",
".",
"ErrUnexpectedEOF",
"\n",
"}",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"else",
"if",
"n",
"==",
"0",
"{",
"return",
"nil",
",",
"io",
".",
"ErrUnexpectedEOF",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // ReadUntilPunctuation reads from the stream until it find a desired
// punctuation byte. If it wasn't found before EOF, it will return io.ErrUnexpectedEOF.
// If it wasn't found before lim bytes are consumed, then it will return ErrOverflow. | [
"ReadUntilPunctuation",
"reads",
"from",
"the",
"stream",
"until",
"it",
"find",
"a",
"desired",
"punctuation",
"byte",
".",
"If",
"it",
"wasn",
"t",
"found",
"before",
"EOF",
"it",
"will",
"return",
"io",
".",
"ErrUnexpectedEOF",
".",
"If",
"it",
"wasn",
"t",
"found",
"before",
"lim",
"bytes",
"are",
"consumed",
"then",
"it",
"will",
"return",
"ErrOverflow",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/punctuated_reader.go#L103-L125 |
1,466 | keybase/saltpack | punctuated_reader.go | newPunctuatedReader | func newPunctuatedReader(r io.Reader, p byte) *punctuatedReader {
ret := &punctuatedReader{r: r}
ret.punctuation[0] = p
return ret
} | go | func newPunctuatedReader(r io.Reader, p byte) *punctuatedReader {
ret := &punctuatedReader{r: r}
ret.punctuation[0] = p
return ret
} | [
"func",
"newPunctuatedReader",
"(",
"r",
"io",
".",
"Reader",
",",
"p",
"byte",
")",
"*",
"punctuatedReader",
"{",
"ret",
":=",
"&",
"punctuatedReader",
"{",
"r",
":",
"r",
"}",
"\n",
"ret",
".",
"punctuation",
"[",
"0",
"]",
"=",
"p",
"\n",
"return",
"ret",
"\n",
"}"
] | // newPunctuatedReader returns a new punctuatedReader given an underlying
// read stream and a punctuation byte. | [
"newPunctuatedReader",
"returns",
"a",
"new",
"punctuatedReader",
"given",
"an",
"underlying",
"read",
"stream",
"and",
"a",
"punctuation",
"byte",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/punctuated_reader.go#L129-L133 |
1,467 | keybase/saltpack | armor62_decrypt.go | NewDearmor62DecryptStream | func NewDearmor62DecryptStream(versionValidator VersionValidator, ciphertext io.Reader, kr Keyring) (*MessageKeyInfo, io.Reader, string, error) {
dearmored, frame, err := NewArmor62DecoderStream(ciphertext, armor62EncryptionHeaderChecker, armor62EncryptionFrameChecker)
if err != nil {
return nil, nil, "", err
}
brand, err := frame.GetBrand()
if err != nil {
return nil, nil, "", err
}
mki, r, err := NewDecryptStream(versionValidator, dearmored, kr)
if err != nil {
return mki, nil, "", err
}
return mki, r, brand, nil
} | go | func NewDearmor62DecryptStream(versionValidator VersionValidator, ciphertext io.Reader, kr Keyring) (*MessageKeyInfo, io.Reader, string, error) {
dearmored, frame, err := NewArmor62DecoderStream(ciphertext, armor62EncryptionHeaderChecker, armor62EncryptionFrameChecker)
if err != nil {
return nil, nil, "", err
}
brand, err := frame.GetBrand()
if err != nil {
return nil, nil, "", err
}
mki, r, err := NewDecryptStream(versionValidator, dearmored, kr)
if err != nil {
return mki, nil, "", err
}
return mki, r, brand, nil
} | [
"func",
"NewDearmor62DecryptStream",
"(",
"versionValidator",
"VersionValidator",
",",
"ciphertext",
"io",
".",
"Reader",
",",
"kr",
"Keyring",
")",
"(",
"*",
"MessageKeyInfo",
",",
"io",
".",
"Reader",
",",
"string",
",",
"error",
")",
"{",
"dearmored",
",",
"frame",
",",
"err",
":=",
"NewArmor62DecoderStream",
"(",
"ciphertext",
",",
"armor62EncryptionHeaderChecker",
",",
"armor62EncryptionFrameChecker",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"brand",
",",
"err",
":=",
"frame",
".",
"GetBrand",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"mki",
",",
"r",
",",
"err",
":=",
"NewDecryptStream",
"(",
"versionValidator",
",",
"dearmored",
",",
"kr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"mki",
",",
"nil",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"mki",
",",
"r",
",",
"brand",
",",
"nil",
"\n",
"}"
] | // NewDearmor62DecryptStream makes a new stream that dearmors and decrypts the given
// Reader stream. Pass it a keyring so that it can lookup private and public keys
// as necessary. Returns the MessageKeyInfo recovered during header
// processing, an io.Reader stream from which you can read the plaintext, the armor branding, and
// maybe an error if there was a failure. | [
"NewDearmor62DecryptStream",
"makes",
"a",
"new",
"stream",
"that",
"dearmors",
"and",
"decrypts",
"the",
"given",
"Reader",
"stream",
".",
"Pass",
"it",
"a",
"keyring",
"so",
"that",
"it",
"can",
"lookup",
"private",
"and",
"public",
"keys",
"as",
"necessary",
".",
"Returns",
"the",
"MessageKeyInfo",
"recovered",
"during",
"header",
"processing",
"an",
"io",
".",
"Reader",
"stream",
"from",
"which",
"you",
"can",
"read",
"the",
"plaintext",
"the",
"armor",
"branding",
"and",
"maybe",
"an",
"error",
"if",
"there",
"was",
"a",
"failure",
"."
] | 0ac0b421a59b0473d103cc659cb8508e946a5f13 | https://github.com/keybase/saltpack/blob/0ac0b421a59b0473d103cc659cb8508e946a5f13/armor62_decrypt.go#L26-L40 |
1,468 | rakyll/gom | internal/report/report.go | Generate | func Generate(w io.Writer, rpt *Report, obj plugin.ObjTool) error {
o := rpt.options
switch o.OutputFormat {
case Dot:
return printDOT(w, rpt)
case Tree:
return printTree(w, rpt)
case Text:
return printText(w, rpt)
case JSON:
return printJSON(w, rpt)
case Raw:
fmt.Fprint(w, rpt.prof.String())
return nil
case Tags:
return printTags(w, rpt)
case Proto:
return rpt.prof.Write(w)
case Dis:
return printAssembly(w, rpt, obj)
case List:
return printSource(w, rpt)
case WebList:
return printWebSource(w, rpt, obj)
case Callgrind:
return printCallgrind(w, rpt)
}
return fmt.Errorf("unexpected output format")
} | go | func Generate(w io.Writer, rpt *Report, obj plugin.ObjTool) error {
o := rpt.options
switch o.OutputFormat {
case Dot:
return printDOT(w, rpt)
case Tree:
return printTree(w, rpt)
case Text:
return printText(w, rpt)
case JSON:
return printJSON(w, rpt)
case Raw:
fmt.Fprint(w, rpt.prof.String())
return nil
case Tags:
return printTags(w, rpt)
case Proto:
return rpt.prof.Write(w)
case Dis:
return printAssembly(w, rpt, obj)
case List:
return printSource(w, rpt)
case WebList:
return printWebSource(w, rpt, obj)
case Callgrind:
return printCallgrind(w, rpt)
}
return fmt.Errorf("unexpected output format")
} | [
"func",
"Generate",
"(",
"w",
"io",
".",
"Writer",
",",
"rpt",
"*",
"Report",
",",
"obj",
"plugin",
".",
"ObjTool",
")",
"error",
"{",
"o",
":=",
"rpt",
".",
"options",
"\n\n",
"switch",
"o",
".",
"OutputFormat",
"{",
"case",
"Dot",
":",
"return",
"printDOT",
"(",
"w",
",",
"rpt",
")",
"\n",
"case",
"Tree",
":",
"return",
"printTree",
"(",
"w",
",",
"rpt",
")",
"\n",
"case",
"Text",
":",
"return",
"printText",
"(",
"w",
",",
"rpt",
")",
"\n",
"case",
"JSON",
":",
"return",
"printJSON",
"(",
"w",
",",
"rpt",
")",
"\n",
"case",
"Raw",
":",
"fmt",
".",
"Fprint",
"(",
"w",
",",
"rpt",
".",
"prof",
".",
"String",
"(",
")",
")",
"\n",
"return",
"nil",
"\n",
"case",
"Tags",
":",
"return",
"printTags",
"(",
"w",
",",
"rpt",
")",
"\n",
"case",
"Proto",
":",
"return",
"rpt",
".",
"prof",
".",
"Write",
"(",
"w",
")",
"\n",
"case",
"Dis",
":",
"return",
"printAssembly",
"(",
"w",
",",
"rpt",
",",
"obj",
")",
"\n",
"case",
"List",
":",
"return",
"printSource",
"(",
"w",
",",
"rpt",
")",
"\n",
"case",
"WebList",
":",
"return",
"printWebSource",
"(",
"w",
",",
"rpt",
",",
"obj",
")",
"\n",
"case",
"Callgrind",
":",
"return",
"printCallgrind",
"(",
"w",
",",
"rpt",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // Generate generates a report as directed by the Report. | [
"Generate",
"generates",
"a",
"report",
"as",
"directed",
"by",
"the",
"Report",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/report/report.go#L27-L56 |
1,469 | rakyll/gom | internal/report/report.go | canAccessFile | func canAccessFile(path string) bool {
if fi, err := os.Stat(path); err == nil {
return fi.Mode().Perm()&0400 != 0
}
return false
} | go | func canAccessFile(path string) bool {
if fi, err := os.Stat(path); err == nil {
return fi.Mode().Perm()&0400 != 0
}
return false
} | [
"func",
"canAccessFile",
"(",
"path",
"string",
")",
"bool",
"{",
"if",
"fi",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"path",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"fi",
".",
"Mode",
"(",
")",
".",
"Perm",
"(",
")",
"&",
"0400",
"!=",
"0",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // canAccessFile determines if the filename can be opened for reading. | [
"canAccessFile",
"determines",
"if",
"the",
"filename",
"can",
"be",
"opened",
"for",
"reading",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/report/report.go#L295-L300 |
1,470 | rakyll/gom | internal/report/report.go | percentage | func percentage(value, total int64) string {
var ratio float64
if total != 0 {
ratio = float64(value) / float64(total) * 100
}
switch {
case ratio >= 99.95:
return " 100%"
case ratio >= 1.0:
return fmt.Sprintf("%5.2f%%", ratio)
default:
return fmt.Sprintf("%5.2g%%", ratio)
}
} | go | func percentage(value, total int64) string {
var ratio float64
if total != 0 {
ratio = float64(value) / float64(total) * 100
}
switch {
case ratio >= 99.95:
return " 100%"
case ratio >= 1.0:
return fmt.Sprintf("%5.2f%%", ratio)
default:
return fmt.Sprintf("%5.2g%%", ratio)
}
} | [
"func",
"percentage",
"(",
"value",
",",
"total",
"int64",
")",
"string",
"{",
"var",
"ratio",
"float64",
"\n",
"if",
"total",
"!=",
"0",
"{",
"ratio",
"=",
"float64",
"(",
"value",
")",
"/",
"float64",
"(",
"total",
")",
"*",
"100",
"\n",
"}",
"\n",
"switch",
"{",
"case",
"ratio",
">=",
"99.95",
":",
"return",
"\"",
"\"",
"\n",
"case",
"ratio",
">=",
"1.0",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ratio",
")",
"\n",
"default",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ratio",
")",
"\n",
"}",
"\n",
"}"
] | // percentage computes the percentage of total of a value, and encodes
// it as a string. At least two digits of precision are printed. | [
"percentage",
"computes",
"the",
"percentage",
"of",
"total",
"of",
"a",
"value",
"and",
"encodes",
"it",
"as",
"a",
"string",
".",
"At",
"least",
"two",
"digits",
"of",
"precision",
"are",
"printed",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/report/report.go#L565-L578 |
1,471 | rakyll/gom | internal/report/report.go | dotLegend | func dotLegend(rpt *Report, g graph, origCount, droppedNodes, droppedEdges int) string {
label := legendLabels(rpt)
label = append(label, legendDetailLabels(rpt, g, origCount, droppedNodes, droppedEdges)...)
return fmt.Sprintf(`subgraph cluster_L { L [shape=box fontsize=32 label="%s\l"] }`, strings.Join(label, `\l`))
} | go | func dotLegend(rpt *Report, g graph, origCount, droppedNodes, droppedEdges int) string {
label := legendLabels(rpt)
label = append(label, legendDetailLabels(rpt, g, origCount, droppedNodes, droppedEdges)...)
return fmt.Sprintf(`subgraph cluster_L { L [shape=box fontsize=32 label="%s\l"] }`, strings.Join(label, `\l`))
} | [
"func",
"dotLegend",
"(",
"rpt",
"*",
"Report",
",",
"g",
"graph",
",",
"origCount",
",",
"droppedNodes",
",",
"droppedEdges",
"int",
")",
"string",
"{",
"label",
":=",
"legendLabels",
"(",
"rpt",
")",
"\n",
"label",
"=",
"append",
"(",
"label",
",",
"legendDetailLabels",
"(",
"rpt",
",",
"g",
",",
"origCount",
",",
"droppedNodes",
",",
"droppedEdges",
")",
"...",
")",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"`subgraph cluster_L { L [shape=box fontsize=32 label=\"%s\\l\"] }`",
",",
"strings",
".",
"Join",
"(",
"label",
",",
"`\\l`",
")",
")",
"\n",
"}"
] | // dotLegend generates the overall graph label for a report in DOT format. | [
"dotLegend",
"generates",
"the",
"overall",
"graph",
"label",
"for",
"a",
"report",
"in",
"DOT",
"format",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/report/report.go#L581-L585 |
1,472 | rakyll/gom | internal/report/report.go | legendLabels | func legendLabels(rpt *Report) []string {
prof := rpt.prof
o := rpt.options
var label []string
if len(prof.Mapping) > 0 {
if prof.Mapping[0].File != "" {
label = append(label, "File: "+filepath.Base(prof.Mapping[0].File))
}
if prof.Mapping[0].BuildID != "" {
label = append(label, "Build ID: "+prof.Mapping[0].BuildID)
}
}
if o.SampleType != "" {
label = append(label, "Type: "+o.SampleType)
}
if prof.TimeNanos != 0 {
const layout = "Jan 2, 2006 at 3:04pm (MST)"
label = append(label, "Time: "+time.Unix(0, prof.TimeNanos).Format(layout))
}
if prof.DurationNanos != 0 {
label = append(label, fmt.Sprintf("Duration: %v", time.Duration(prof.DurationNanos)))
}
return label
} | go | func legendLabels(rpt *Report) []string {
prof := rpt.prof
o := rpt.options
var label []string
if len(prof.Mapping) > 0 {
if prof.Mapping[0].File != "" {
label = append(label, "File: "+filepath.Base(prof.Mapping[0].File))
}
if prof.Mapping[0].BuildID != "" {
label = append(label, "Build ID: "+prof.Mapping[0].BuildID)
}
}
if o.SampleType != "" {
label = append(label, "Type: "+o.SampleType)
}
if prof.TimeNanos != 0 {
const layout = "Jan 2, 2006 at 3:04pm (MST)"
label = append(label, "Time: "+time.Unix(0, prof.TimeNanos).Format(layout))
}
if prof.DurationNanos != 0 {
label = append(label, fmt.Sprintf("Duration: %v", time.Duration(prof.DurationNanos)))
}
return label
} | [
"func",
"legendLabels",
"(",
"rpt",
"*",
"Report",
")",
"[",
"]",
"string",
"{",
"prof",
":=",
"rpt",
".",
"prof",
"\n",
"o",
":=",
"rpt",
".",
"options",
"\n",
"var",
"label",
"[",
"]",
"string",
"\n",
"if",
"len",
"(",
"prof",
".",
"Mapping",
")",
">",
"0",
"{",
"if",
"prof",
".",
"Mapping",
"[",
"0",
"]",
".",
"File",
"!=",
"\"",
"\"",
"{",
"label",
"=",
"append",
"(",
"label",
",",
"\"",
"\"",
"+",
"filepath",
".",
"Base",
"(",
"prof",
".",
"Mapping",
"[",
"0",
"]",
".",
"File",
")",
")",
"\n",
"}",
"\n",
"if",
"prof",
".",
"Mapping",
"[",
"0",
"]",
".",
"BuildID",
"!=",
"\"",
"\"",
"{",
"label",
"=",
"append",
"(",
"label",
",",
"\"",
"\"",
"+",
"prof",
".",
"Mapping",
"[",
"0",
"]",
".",
"BuildID",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"o",
".",
"SampleType",
"!=",
"\"",
"\"",
"{",
"label",
"=",
"append",
"(",
"label",
",",
"\"",
"\"",
"+",
"o",
".",
"SampleType",
")",
"\n",
"}",
"\n",
"if",
"prof",
".",
"TimeNanos",
"!=",
"0",
"{",
"const",
"layout",
"=",
"\"",
"\"",
"\n",
"label",
"=",
"append",
"(",
"label",
",",
"\"",
"\"",
"+",
"time",
".",
"Unix",
"(",
"0",
",",
"prof",
".",
"TimeNanos",
")",
".",
"Format",
"(",
"layout",
")",
")",
"\n",
"}",
"\n",
"if",
"prof",
".",
"DurationNanos",
"!=",
"0",
"{",
"label",
"=",
"append",
"(",
"label",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"time",
".",
"Duration",
"(",
"prof",
".",
"DurationNanos",
")",
")",
")",
"\n",
"}",
"\n",
"return",
"label",
"\n",
"}"
] | // legendLabels generates labels exclusive to graph visualization. | [
"legendLabels",
"generates",
"labels",
"exclusive",
"to",
"graph",
"visualization",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/report/report.go#L588-L611 |
1,473 | rakyll/gom | internal/report/report.go | legendDetailLabels | func legendDetailLabels(rpt *Report, g graph, origCount, droppedNodes, droppedEdges int) []string {
nodeFraction := rpt.options.NodeFraction
edgeFraction := rpt.options.EdgeFraction
nodeCount := rpt.options.NodeCount
label := []string{}
var flatSum int64
for _, n := range g.ns {
flatSum = flatSum + n.flat
}
label = append(label, fmt.Sprintf("%s of %s total (%s)", rpt.formatValue(flatSum), rpt.formatValue(rpt.total), percentage(flatSum, rpt.total)))
if rpt.total > 0 {
if droppedNodes > 0 {
label = append(label, genLabel(droppedNodes, "node", "cum",
rpt.formatValue(int64(float64(rpt.total)*nodeFraction))))
}
if droppedEdges > 0 {
label = append(label, genLabel(droppedEdges, "edge", "freq",
rpt.formatValue(int64(float64(rpt.total)*edgeFraction))))
}
if nodeCount > 0 && nodeCount < origCount {
label = append(label, fmt.Sprintf("Showing top %d nodes out of %d (cum >= %s)",
nodeCount, origCount,
rpt.formatValue(g.ns[len(g.ns)-1].cum)))
}
}
return label
} | go | func legendDetailLabels(rpt *Report, g graph, origCount, droppedNodes, droppedEdges int) []string {
nodeFraction := rpt.options.NodeFraction
edgeFraction := rpt.options.EdgeFraction
nodeCount := rpt.options.NodeCount
label := []string{}
var flatSum int64
for _, n := range g.ns {
flatSum = flatSum + n.flat
}
label = append(label, fmt.Sprintf("%s of %s total (%s)", rpt.formatValue(flatSum), rpt.formatValue(rpt.total), percentage(flatSum, rpt.total)))
if rpt.total > 0 {
if droppedNodes > 0 {
label = append(label, genLabel(droppedNodes, "node", "cum",
rpt.formatValue(int64(float64(rpt.total)*nodeFraction))))
}
if droppedEdges > 0 {
label = append(label, genLabel(droppedEdges, "edge", "freq",
rpt.formatValue(int64(float64(rpt.total)*edgeFraction))))
}
if nodeCount > 0 && nodeCount < origCount {
label = append(label, fmt.Sprintf("Showing top %d nodes out of %d (cum >= %s)",
nodeCount, origCount,
rpt.formatValue(g.ns[len(g.ns)-1].cum)))
}
}
return label
} | [
"func",
"legendDetailLabels",
"(",
"rpt",
"*",
"Report",
",",
"g",
"graph",
",",
"origCount",
",",
"droppedNodes",
",",
"droppedEdges",
"int",
")",
"[",
"]",
"string",
"{",
"nodeFraction",
":=",
"rpt",
".",
"options",
".",
"NodeFraction",
"\n",
"edgeFraction",
":=",
"rpt",
".",
"options",
".",
"EdgeFraction",
"\n",
"nodeCount",
":=",
"rpt",
".",
"options",
".",
"NodeCount",
"\n\n",
"label",
":=",
"[",
"]",
"string",
"{",
"}",
"\n\n",
"var",
"flatSum",
"int64",
"\n",
"for",
"_",
",",
"n",
":=",
"range",
"g",
".",
"ns",
"{",
"flatSum",
"=",
"flatSum",
"+",
"n",
".",
"flat",
"\n",
"}",
"\n\n",
"label",
"=",
"append",
"(",
"label",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"rpt",
".",
"formatValue",
"(",
"flatSum",
")",
",",
"rpt",
".",
"formatValue",
"(",
"rpt",
".",
"total",
")",
",",
"percentage",
"(",
"flatSum",
",",
"rpt",
".",
"total",
")",
")",
")",
"\n\n",
"if",
"rpt",
".",
"total",
">",
"0",
"{",
"if",
"droppedNodes",
">",
"0",
"{",
"label",
"=",
"append",
"(",
"label",
",",
"genLabel",
"(",
"droppedNodes",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"rpt",
".",
"formatValue",
"(",
"int64",
"(",
"float64",
"(",
"rpt",
".",
"total",
")",
"*",
"nodeFraction",
")",
")",
")",
")",
"\n",
"}",
"\n",
"if",
"droppedEdges",
">",
"0",
"{",
"label",
"=",
"append",
"(",
"label",
",",
"genLabel",
"(",
"droppedEdges",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"rpt",
".",
"formatValue",
"(",
"int64",
"(",
"float64",
"(",
"rpt",
".",
"total",
")",
"*",
"edgeFraction",
")",
")",
")",
")",
"\n",
"}",
"\n",
"if",
"nodeCount",
">",
"0",
"&&",
"nodeCount",
"<",
"origCount",
"{",
"label",
"=",
"append",
"(",
"label",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"nodeCount",
",",
"origCount",
",",
"rpt",
".",
"formatValue",
"(",
"g",
".",
"ns",
"[",
"len",
"(",
"g",
".",
"ns",
")",
"-",
"1",
"]",
".",
"cum",
")",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"label",
"\n",
"}"
] | // legendDetailLabels generates labels common to graph and text visualization. | [
"legendDetailLabels",
"generates",
"labels",
"common",
"to",
"graph",
"and",
"text",
"visualization",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/report/report.go#L614-L644 |
1,474 | rakyll/gom | internal/report/report.go | dotNode | func dotNode(rpt *Report, maxFlat float64, rIndex int, n *node) string {
flat, cum := n.flat, n.cum
labels := strings.Split(n.info.prettyName(), "::")
label := strings.Join(labels, `\n`) + `\n`
flatValue := rpt.formatValue(flat)
if flat > 0 {
label = label + fmt.Sprintf(`%s(%s)`,
flatValue,
strings.TrimSpace(percentage(flat, rpt.total)))
} else {
label = label + "0"
}
cumValue := flatValue
if cum != flat {
if flat > 0 {
label = label + `\n`
} else {
label = label + " "
}
cumValue = rpt.formatValue(cum)
label = label + fmt.Sprintf(`of %s(%s)`,
cumValue,
strings.TrimSpace(percentage(cum, rpt.total)))
}
// Scale font sizes from 8 to 24 based on percentage of flat frequency.
// Use non linear growth to emphasize the size difference.
baseFontSize, maxFontGrowth := 8, 16.0
fontSize := baseFontSize
if maxFlat > 0 && flat > 0 && float64(flat) <= maxFlat {
fontSize += int(math.Ceil(maxFontGrowth * math.Sqrt(float64(flat)/maxFlat)))
}
return fmt.Sprintf(`N%d [label="%s" fontsize=%d shape=box tooltip="%s (%s)"]`,
rIndex,
label,
fontSize, n.info.prettyName(), cumValue)
} | go | func dotNode(rpt *Report, maxFlat float64, rIndex int, n *node) string {
flat, cum := n.flat, n.cum
labels := strings.Split(n.info.prettyName(), "::")
label := strings.Join(labels, `\n`) + `\n`
flatValue := rpt.formatValue(flat)
if flat > 0 {
label = label + fmt.Sprintf(`%s(%s)`,
flatValue,
strings.TrimSpace(percentage(flat, rpt.total)))
} else {
label = label + "0"
}
cumValue := flatValue
if cum != flat {
if flat > 0 {
label = label + `\n`
} else {
label = label + " "
}
cumValue = rpt.formatValue(cum)
label = label + fmt.Sprintf(`of %s(%s)`,
cumValue,
strings.TrimSpace(percentage(cum, rpt.total)))
}
// Scale font sizes from 8 to 24 based on percentage of flat frequency.
// Use non linear growth to emphasize the size difference.
baseFontSize, maxFontGrowth := 8, 16.0
fontSize := baseFontSize
if maxFlat > 0 && flat > 0 && float64(flat) <= maxFlat {
fontSize += int(math.Ceil(maxFontGrowth * math.Sqrt(float64(flat)/maxFlat)))
}
return fmt.Sprintf(`N%d [label="%s" fontsize=%d shape=box tooltip="%s (%s)"]`,
rIndex,
label,
fontSize, n.info.prettyName(), cumValue)
} | [
"func",
"dotNode",
"(",
"rpt",
"*",
"Report",
",",
"maxFlat",
"float64",
",",
"rIndex",
"int",
",",
"n",
"*",
"node",
")",
"string",
"{",
"flat",
",",
"cum",
":=",
"n",
".",
"flat",
",",
"n",
".",
"cum",
"\n\n",
"labels",
":=",
"strings",
".",
"Split",
"(",
"n",
".",
"info",
".",
"prettyName",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"label",
":=",
"strings",
".",
"Join",
"(",
"labels",
",",
"`\\n`",
")",
"+",
"`\\n`",
"\n\n",
"flatValue",
":=",
"rpt",
".",
"formatValue",
"(",
"flat",
")",
"\n",
"if",
"flat",
">",
"0",
"{",
"label",
"=",
"label",
"+",
"fmt",
".",
"Sprintf",
"(",
"`%s(%s)`",
",",
"flatValue",
",",
"strings",
".",
"TrimSpace",
"(",
"percentage",
"(",
"flat",
",",
"rpt",
".",
"total",
")",
")",
")",
"\n",
"}",
"else",
"{",
"label",
"=",
"label",
"+",
"\"",
"\"",
"\n",
"}",
"\n",
"cumValue",
":=",
"flatValue",
"\n",
"if",
"cum",
"!=",
"flat",
"{",
"if",
"flat",
">",
"0",
"{",
"label",
"=",
"label",
"+",
"`\\n`",
"\n",
"}",
"else",
"{",
"label",
"=",
"label",
"+",
"\"",
"\"",
"\n",
"}",
"\n",
"cumValue",
"=",
"rpt",
".",
"formatValue",
"(",
"cum",
")",
"\n",
"label",
"=",
"label",
"+",
"fmt",
".",
"Sprintf",
"(",
"`of %s(%s)`",
",",
"cumValue",
",",
"strings",
".",
"TrimSpace",
"(",
"percentage",
"(",
"cum",
",",
"rpt",
".",
"total",
")",
")",
")",
"\n",
"}",
"\n\n",
"// Scale font sizes from 8 to 24 based on percentage of flat frequency.",
"// Use non linear growth to emphasize the size difference.",
"baseFontSize",
",",
"maxFontGrowth",
":=",
"8",
",",
"16.0",
"\n",
"fontSize",
":=",
"baseFontSize",
"\n",
"if",
"maxFlat",
">",
"0",
"&&",
"flat",
">",
"0",
"&&",
"float64",
"(",
"flat",
")",
"<=",
"maxFlat",
"{",
"fontSize",
"+=",
"int",
"(",
"math",
".",
"Ceil",
"(",
"maxFontGrowth",
"*",
"math",
".",
"Sqrt",
"(",
"float64",
"(",
"flat",
")",
"/",
"maxFlat",
")",
")",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"`N%d [label=\"%s\" fontsize=%d shape=box tooltip=\"%s (%s)\"]`",
",",
"rIndex",
",",
"label",
",",
"fontSize",
",",
"n",
".",
"info",
".",
"prettyName",
"(",
")",
",",
"cumValue",
")",
"\n",
"}"
] | // dotNode generates a graph node in DOT format. | [
"dotNode",
"generates",
"a",
"graph",
"node",
"in",
"DOT",
"format",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/report/report.go#L654-L692 |
1,475 | rakyll/gom | internal/report/report.go | dotEdge | func dotEdge(rpt *Report, from, to int, e *edgeInfo) string {
w := rpt.formatValue(e.weight)
attr := fmt.Sprintf(`label=" %s"`, w)
if rpt.total > 0 {
if weight := 1 + int(e.weight*100/rpt.total); weight > 1 {
attr = fmt.Sprintf(`%s weight=%d`, attr, weight)
}
if width := 1 + int(e.weight*5/rpt.total); width > 1 {
attr = fmt.Sprintf(`%s penwidth=%d`, attr, width)
}
}
arrow := "->"
if e.residual {
arrow = "..."
}
tooltip := fmt.Sprintf(`"%s %s %s (%s)"`,
e.src.info.prettyName(), arrow, e.dest.info.prettyName(), w)
attr = fmt.Sprintf(`%s tooltip=%s labeltooltip=%s`,
attr, tooltip, tooltip)
if e.residual {
attr = attr + ` style="dotted"`
}
if len(e.src.tags) > 0 {
// Separate children further if source has tags.
attr = attr + " minlen=2"
}
return fmt.Sprintf("N%d -> N%d [%s]", from, to, attr)
} | go | func dotEdge(rpt *Report, from, to int, e *edgeInfo) string {
w := rpt.formatValue(e.weight)
attr := fmt.Sprintf(`label=" %s"`, w)
if rpt.total > 0 {
if weight := 1 + int(e.weight*100/rpt.total); weight > 1 {
attr = fmt.Sprintf(`%s weight=%d`, attr, weight)
}
if width := 1 + int(e.weight*5/rpt.total); width > 1 {
attr = fmt.Sprintf(`%s penwidth=%d`, attr, width)
}
}
arrow := "->"
if e.residual {
arrow = "..."
}
tooltip := fmt.Sprintf(`"%s %s %s (%s)"`,
e.src.info.prettyName(), arrow, e.dest.info.prettyName(), w)
attr = fmt.Sprintf(`%s tooltip=%s labeltooltip=%s`,
attr, tooltip, tooltip)
if e.residual {
attr = attr + ` style="dotted"`
}
if len(e.src.tags) > 0 {
// Separate children further if source has tags.
attr = attr + " minlen=2"
}
return fmt.Sprintf("N%d -> N%d [%s]", from, to, attr)
} | [
"func",
"dotEdge",
"(",
"rpt",
"*",
"Report",
",",
"from",
",",
"to",
"int",
",",
"e",
"*",
"edgeInfo",
")",
"string",
"{",
"w",
":=",
"rpt",
".",
"formatValue",
"(",
"e",
".",
"weight",
")",
"\n",
"attr",
":=",
"fmt",
".",
"Sprintf",
"(",
"`label=\" %s\"`",
",",
"w",
")",
"\n",
"if",
"rpt",
".",
"total",
">",
"0",
"{",
"if",
"weight",
":=",
"1",
"+",
"int",
"(",
"e",
".",
"weight",
"*",
"100",
"/",
"rpt",
".",
"total",
")",
";",
"weight",
">",
"1",
"{",
"attr",
"=",
"fmt",
".",
"Sprintf",
"(",
"`%s weight=%d`",
",",
"attr",
",",
"weight",
")",
"\n",
"}",
"\n",
"if",
"width",
":=",
"1",
"+",
"int",
"(",
"e",
".",
"weight",
"*",
"5",
"/",
"rpt",
".",
"total",
")",
";",
"width",
">",
"1",
"{",
"attr",
"=",
"fmt",
".",
"Sprintf",
"(",
"`%s penwidth=%d`",
",",
"attr",
",",
"width",
")",
"\n",
"}",
"\n",
"}",
"\n",
"arrow",
":=",
"\"",
"\"",
"\n",
"if",
"e",
".",
"residual",
"{",
"arrow",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"tooltip",
":=",
"fmt",
".",
"Sprintf",
"(",
"`\"%s %s %s (%s)\"`",
",",
"e",
".",
"src",
".",
"info",
".",
"prettyName",
"(",
")",
",",
"arrow",
",",
"e",
".",
"dest",
".",
"info",
".",
"prettyName",
"(",
")",
",",
"w",
")",
"\n",
"attr",
"=",
"fmt",
".",
"Sprintf",
"(",
"`%s tooltip=%s labeltooltip=%s`",
",",
"attr",
",",
"tooltip",
",",
"tooltip",
")",
"\n\n",
"if",
"e",
".",
"residual",
"{",
"attr",
"=",
"attr",
"+",
"` style=\"dotted\"`",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"e",
".",
"src",
".",
"tags",
")",
">",
"0",
"{",
"// Separate children further if source has tags.",
"attr",
"=",
"attr",
"+",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"from",
",",
"to",
",",
"attr",
")",
"\n",
"}"
] | // dotEdge generates a graph edge in DOT format. | [
"dotEdge",
"generates",
"a",
"graph",
"edge",
"in",
"DOT",
"format",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/report/report.go#L695-L724 |
1,476 | rakyll/gom | internal/report/report.go | dotNodelets | func dotNodelets(rpt *Report, rIndex int, n *node) (dot string) {
const maxNodelets = 4 // Number of nodelets for alphanumeric labels
const maxNumNodelets = 4 // Number of nodelets for numeric labels
var ts, nts tags
for _, t := range n.tags {
if t.unit == "" {
ts = append(ts, t)
} else {
nts = append(nts, t)
}
}
// Select the top maxNodelets alphanumeric labels by weight
sort.Sort(ts)
if len(ts) > maxNodelets {
ts = ts[:maxNodelets]
}
for i, t := range ts {
weight := rpt.formatValue(t.weight)
dot += fmt.Sprintf(`N%d_%d [label = "%s" fontsize=8 shape=box3d tooltip="%s"]`+"\n", rIndex, i, t.name, weight)
dot += fmt.Sprintf(`N%d -> N%d_%d [label=" %s" weight=100 tooltip="\L" labeltooltip="\L"]`+"\n", rIndex, rIndex, i, weight)
}
// Collapse numeric labels into maxNumNodelets buckets, of the form:
// 1MB..2MB, 3MB..5MB, ...
nts = collapseTags(nts, maxNumNodelets)
sort.Sort(nts)
for i, t := range nts {
weight := rpt.formatValue(t.weight)
dot += fmt.Sprintf(`NN%d_%d [label = "%s" fontsize=8 shape=box3d tooltip="%s"]`+"\n", rIndex, i, t.name, weight)
dot += fmt.Sprintf(`N%d -> NN%d_%d [label=" %s" weight=100 tooltip="\L" labeltooltip="\L"]`+"\n", rIndex, rIndex, i, weight)
}
return dot
} | go | func dotNodelets(rpt *Report, rIndex int, n *node) (dot string) {
const maxNodelets = 4 // Number of nodelets for alphanumeric labels
const maxNumNodelets = 4 // Number of nodelets for numeric labels
var ts, nts tags
for _, t := range n.tags {
if t.unit == "" {
ts = append(ts, t)
} else {
nts = append(nts, t)
}
}
// Select the top maxNodelets alphanumeric labels by weight
sort.Sort(ts)
if len(ts) > maxNodelets {
ts = ts[:maxNodelets]
}
for i, t := range ts {
weight := rpt.formatValue(t.weight)
dot += fmt.Sprintf(`N%d_%d [label = "%s" fontsize=8 shape=box3d tooltip="%s"]`+"\n", rIndex, i, t.name, weight)
dot += fmt.Sprintf(`N%d -> N%d_%d [label=" %s" weight=100 tooltip="\L" labeltooltip="\L"]`+"\n", rIndex, rIndex, i, weight)
}
// Collapse numeric labels into maxNumNodelets buckets, of the form:
// 1MB..2MB, 3MB..5MB, ...
nts = collapseTags(nts, maxNumNodelets)
sort.Sort(nts)
for i, t := range nts {
weight := rpt.formatValue(t.weight)
dot += fmt.Sprintf(`NN%d_%d [label = "%s" fontsize=8 shape=box3d tooltip="%s"]`+"\n", rIndex, i, t.name, weight)
dot += fmt.Sprintf(`N%d -> NN%d_%d [label=" %s" weight=100 tooltip="\L" labeltooltip="\L"]`+"\n", rIndex, rIndex, i, weight)
}
return dot
} | [
"func",
"dotNodelets",
"(",
"rpt",
"*",
"Report",
",",
"rIndex",
"int",
",",
"n",
"*",
"node",
")",
"(",
"dot",
"string",
")",
"{",
"const",
"maxNodelets",
"=",
"4",
"// Number of nodelets for alphanumeric labels",
"\n",
"const",
"maxNumNodelets",
"=",
"4",
"// Number of nodelets for numeric labels",
"\n\n",
"var",
"ts",
",",
"nts",
"tags",
"\n",
"for",
"_",
",",
"t",
":=",
"range",
"n",
".",
"tags",
"{",
"if",
"t",
".",
"unit",
"==",
"\"",
"\"",
"{",
"ts",
"=",
"append",
"(",
"ts",
",",
"t",
")",
"\n",
"}",
"else",
"{",
"nts",
"=",
"append",
"(",
"nts",
",",
"t",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Select the top maxNodelets alphanumeric labels by weight",
"sort",
".",
"Sort",
"(",
"ts",
")",
"\n",
"if",
"len",
"(",
"ts",
")",
">",
"maxNodelets",
"{",
"ts",
"=",
"ts",
"[",
":",
"maxNodelets",
"]",
"\n",
"}",
"\n",
"for",
"i",
",",
"t",
":=",
"range",
"ts",
"{",
"weight",
":=",
"rpt",
".",
"formatValue",
"(",
"t",
".",
"weight",
")",
"\n",
"dot",
"+=",
"fmt",
".",
"Sprintf",
"(",
"`N%d_%d [label = \"%s\" fontsize=8 shape=box3d tooltip=\"%s\"]`",
"+",
"\"",
"\\n",
"\"",
",",
"rIndex",
",",
"i",
",",
"t",
".",
"name",
",",
"weight",
")",
"\n",
"dot",
"+=",
"fmt",
".",
"Sprintf",
"(",
"`N%d -> N%d_%d [label=\" %s\" weight=100 tooltip=\"\\L\" labeltooltip=\"\\L\"]`",
"+",
"\"",
"\\n",
"\"",
",",
"rIndex",
",",
"rIndex",
",",
"i",
",",
"weight",
")",
"\n",
"}",
"\n\n",
"// Collapse numeric labels into maxNumNodelets buckets, of the form:",
"// 1MB..2MB, 3MB..5MB, ...",
"nts",
"=",
"collapseTags",
"(",
"nts",
",",
"maxNumNodelets",
")",
"\n",
"sort",
".",
"Sort",
"(",
"nts",
")",
"\n",
"for",
"i",
",",
"t",
":=",
"range",
"nts",
"{",
"weight",
":=",
"rpt",
".",
"formatValue",
"(",
"t",
".",
"weight",
")",
"\n",
"dot",
"+=",
"fmt",
".",
"Sprintf",
"(",
"`NN%d_%d [label = \"%s\" fontsize=8 shape=box3d tooltip=\"%s\"]`",
"+",
"\"",
"\\n",
"\"",
",",
"rIndex",
",",
"i",
",",
"t",
".",
"name",
",",
"weight",
")",
"\n",
"dot",
"+=",
"fmt",
".",
"Sprintf",
"(",
"`N%d -> NN%d_%d [label=\" %s\" weight=100 tooltip=\"\\L\" labeltooltip=\"\\L\"]`",
"+",
"\"",
"\\n",
"\"",
",",
"rIndex",
",",
"rIndex",
",",
"i",
",",
"weight",
")",
"\n",
"}",
"\n\n",
"return",
"dot",
"\n",
"}"
] | // dotNodelets generates the DOT boxes for the node tags. | [
"dotNodelets",
"generates",
"the",
"DOT",
"boxes",
"for",
"the",
"node",
"tags",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/report/report.go#L727-L762 |
1,477 | rakyll/gom | internal/report/report.go | collapseTags | func collapseTags(ts tags, count int) tags {
if len(ts) <= count {
return ts
}
sort.Sort(ts)
tagGroups := make([]tags, count)
for i, t := range ts[:count] {
tagGroups[i] = tags{t}
}
for _, t := range ts[count:] {
g, d := 0, tagDistance(t, tagGroups[0][0])
for i := 1; i < count; i++ {
if nd := tagDistance(t, tagGroups[i][0]); nd < d {
g, d = i, nd
}
}
tagGroups[g] = append(tagGroups[g], t)
}
var nts tags
for _, g := range tagGroups {
l, w := tagGroupLabel(g)
nts = append(nts, &tag{
name: l,
weight: w,
})
}
return nts
} | go | func collapseTags(ts tags, count int) tags {
if len(ts) <= count {
return ts
}
sort.Sort(ts)
tagGroups := make([]tags, count)
for i, t := range ts[:count] {
tagGroups[i] = tags{t}
}
for _, t := range ts[count:] {
g, d := 0, tagDistance(t, tagGroups[0][0])
for i := 1; i < count; i++ {
if nd := tagDistance(t, tagGroups[i][0]); nd < d {
g, d = i, nd
}
}
tagGroups[g] = append(tagGroups[g], t)
}
var nts tags
for _, g := range tagGroups {
l, w := tagGroupLabel(g)
nts = append(nts, &tag{
name: l,
weight: w,
})
}
return nts
} | [
"func",
"collapseTags",
"(",
"ts",
"tags",
",",
"count",
"int",
")",
"tags",
"{",
"if",
"len",
"(",
"ts",
")",
"<=",
"count",
"{",
"return",
"ts",
"\n",
"}",
"\n\n",
"sort",
".",
"Sort",
"(",
"ts",
")",
"\n",
"tagGroups",
":=",
"make",
"(",
"[",
"]",
"tags",
",",
"count",
")",
"\n",
"for",
"i",
",",
"t",
":=",
"range",
"ts",
"[",
":",
"count",
"]",
"{",
"tagGroups",
"[",
"i",
"]",
"=",
"tags",
"{",
"t",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"t",
":=",
"range",
"ts",
"[",
"count",
":",
"]",
"{",
"g",
",",
"d",
":=",
"0",
",",
"tagDistance",
"(",
"t",
",",
"tagGroups",
"[",
"0",
"]",
"[",
"0",
"]",
")",
"\n",
"for",
"i",
":=",
"1",
";",
"i",
"<",
"count",
";",
"i",
"++",
"{",
"if",
"nd",
":=",
"tagDistance",
"(",
"t",
",",
"tagGroups",
"[",
"i",
"]",
"[",
"0",
"]",
")",
";",
"nd",
"<",
"d",
"{",
"g",
",",
"d",
"=",
"i",
",",
"nd",
"\n",
"}",
"\n",
"}",
"\n",
"tagGroups",
"[",
"g",
"]",
"=",
"append",
"(",
"tagGroups",
"[",
"g",
"]",
",",
"t",
")",
"\n",
"}",
"\n\n",
"var",
"nts",
"tags",
"\n",
"for",
"_",
",",
"g",
":=",
"range",
"tagGroups",
"{",
"l",
",",
"w",
":=",
"tagGroupLabel",
"(",
"g",
")",
"\n",
"nts",
"=",
"append",
"(",
"nts",
",",
"&",
"tag",
"{",
"name",
":",
"l",
",",
"weight",
":",
"w",
",",
"}",
")",
"\n",
"}",
"\n",
"return",
"nts",
"\n",
"}"
] | // collapseTags reduces the number of entries in a tagMap by merging
// adjacent nodes into ranges. It uses a greedy approach to merge
// starting with the entries with the lowest weight. | [
"collapseTags",
"reduces",
"the",
"number",
"of",
"entries",
"in",
"a",
"tagMap",
"by",
"merging",
"adjacent",
"nodes",
"into",
"ranges",
".",
"It",
"uses",
"a",
"greedy",
"approach",
"to",
"merge",
"starting",
"with",
"the",
"entries",
"with",
"the",
"lowest",
"weight",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/report/report.go#L869-L898 |
1,478 | rakyll/gom | internal/report/report.go | sumNodes | func sumNodes(ns nodes) (flat int64, cum int64) {
for _, n := range ns {
flat += n.flat
cum += n.cum
}
return
} | go | func sumNodes(ns nodes) (flat int64, cum int64) {
for _, n := range ns {
flat += n.flat
cum += n.cum
}
return
} | [
"func",
"sumNodes",
"(",
"ns",
"nodes",
")",
"(",
"flat",
"int64",
",",
"cum",
"int64",
")",
"{",
"for",
"_",
",",
"n",
":=",
"range",
"ns",
"{",
"flat",
"+=",
"n",
".",
"flat",
"\n",
"cum",
"+=",
"n",
".",
"cum",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // sumNodes adds the flat and sum values on a report. | [
"sumNodes",
"adds",
"the",
"flat",
"and",
"sum",
"values",
"on",
"a",
"report",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/report/report.go#L930-L936 |
1,479 | rakyll/gom | internal/report/report.go | bumpWeight | func bumpWeight(from, to *node, w int64, residual bool) {
if from.out[to] != to.in[from] {
panic(fmt.Errorf("asymmetric edges %v %v", *from, *to))
}
if n := from.out[to]; n != nil {
n.weight += w
if n.residual && !residual {
n.residual = false
}
return
}
info := &edgeInfo{src: from, dest: to, weight: w, residual: residual}
from.out[to] = info
to.in[from] = info
} | go | func bumpWeight(from, to *node, w int64, residual bool) {
if from.out[to] != to.in[from] {
panic(fmt.Errorf("asymmetric edges %v %v", *from, *to))
}
if n := from.out[to]; n != nil {
n.weight += w
if n.residual && !residual {
n.residual = false
}
return
}
info := &edgeInfo{src: from, dest: to, weight: w, residual: residual}
from.out[to] = info
to.in[from] = info
} | [
"func",
"bumpWeight",
"(",
"from",
",",
"to",
"*",
"node",
",",
"w",
"int64",
",",
"residual",
"bool",
")",
"{",
"if",
"from",
".",
"out",
"[",
"to",
"]",
"!=",
"to",
".",
"in",
"[",
"from",
"]",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"*",
"from",
",",
"*",
"to",
")",
")",
"\n",
"}",
"\n\n",
"if",
"n",
":=",
"from",
".",
"out",
"[",
"to",
"]",
";",
"n",
"!=",
"nil",
"{",
"n",
".",
"weight",
"+=",
"w",
"\n",
"if",
"n",
".",
"residual",
"&&",
"!",
"residual",
"{",
"n",
".",
"residual",
"=",
"false",
"\n",
"}",
"\n",
"return",
"\n",
"}",
"\n\n",
"info",
":=",
"&",
"edgeInfo",
"{",
"src",
":",
"from",
",",
"dest",
":",
"to",
",",
"weight",
":",
"w",
",",
"residual",
":",
"residual",
"}",
"\n",
"from",
".",
"out",
"[",
"to",
"]",
"=",
"info",
"\n",
"to",
".",
"in",
"[",
"from",
"]",
"=",
"info",
"\n",
"}"
] | // bumpWeight increases the weight of an edge. If there isn't such an
// edge in the map one is created. | [
"bumpWeight",
"increases",
"the",
"weight",
"of",
"an",
"edge",
".",
"If",
"there",
"isn",
"t",
"such",
"an",
"edge",
"in",
"the",
"map",
"one",
"is",
"created",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/report/report.go#L952-L968 |
1,480 | rakyll/gom | internal/report/report.go | newGraph | func newGraph(rpt *Report) (g graph, err error) {
prof := rpt.prof
o := rpt.options
// Generate a tree for graphical output if requested.
buildTree := o.CallTree && o.OutputFormat == Dot
locations := make(map[uint64][]nodeInfo)
for _, l := range prof.Location {
locations[l.ID] = newLocInfo(l)
}
nm := make(nodeMap)
for _, sample := range prof.Sample {
if sample.Location == nil {
continue
}
// Construct list of node names for sample.
var stack []nodeInfo
for _, loc := range sample.Location {
id := loc.ID
stack = append(stack, locations[id]...)
}
// Upfront pass to update the parent chains, to prevent the
// merging of nodes with different parents.
if buildTree {
var nn *node
for i := len(stack); i > 0; i-- {
n := &stack[i-1]
n.parent = nn
nn = nm.findOrInsertNode(*n)
}
}
leaf := nm.findOrInsertNode(stack[0])
weight := rpt.sampleValue(sample)
leaf.addTags(sample, weight)
// Aggregate counter data.
leaf.flat += weight
seen := make(map[*node]bool)
var nn *node
for _, s := range stack {
n := nm.findOrInsertNode(s)
if !seen[n] {
seen[n] = true
n.cum += weight
if nn != nil {
bumpWeight(n, nn, weight, false)
}
}
nn = n
}
}
// Collect new nodes into a report.
ns := make(nodes, 0, len(nm))
for _, n := range nm {
if rpt.options.DropNegative && n.flat < 0 {
continue
}
ns = append(ns, n)
}
return graph{ns}, nil
} | go | func newGraph(rpt *Report) (g graph, err error) {
prof := rpt.prof
o := rpt.options
// Generate a tree for graphical output if requested.
buildTree := o.CallTree && o.OutputFormat == Dot
locations := make(map[uint64][]nodeInfo)
for _, l := range prof.Location {
locations[l.ID] = newLocInfo(l)
}
nm := make(nodeMap)
for _, sample := range prof.Sample {
if sample.Location == nil {
continue
}
// Construct list of node names for sample.
var stack []nodeInfo
for _, loc := range sample.Location {
id := loc.ID
stack = append(stack, locations[id]...)
}
// Upfront pass to update the parent chains, to prevent the
// merging of nodes with different parents.
if buildTree {
var nn *node
for i := len(stack); i > 0; i-- {
n := &stack[i-1]
n.parent = nn
nn = nm.findOrInsertNode(*n)
}
}
leaf := nm.findOrInsertNode(stack[0])
weight := rpt.sampleValue(sample)
leaf.addTags(sample, weight)
// Aggregate counter data.
leaf.flat += weight
seen := make(map[*node]bool)
var nn *node
for _, s := range stack {
n := nm.findOrInsertNode(s)
if !seen[n] {
seen[n] = true
n.cum += weight
if nn != nil {
bumpWeight(n, nn, weight, false)
}
}
nn = n
}
}
// Collect new nodes into a report.
ns := make(nodes, 0, len(nm))
for _, n := range nm {
if rpt.options.DropNegative && n.flat < 0 {
continue
}
ns = append(ns, n)
}
return graph{ns}, nil
} | [
"func",
"newGraph",
"(",
"rpt",
"*",
"Report",
")",
"(",
"g",
"graph",
",",
"err",
"error",
")",
"{",
"prof",
":=",
"rpt",
".",
"prof",
"\n",
"o",
":=",
"rpt",
".",
"options",
"\n\n",
"// Generate a tree for graphical output if requested.",
"buildTree",
":=",
"o",
".",
"CallTree",
"&&",
"o",
".",
"OutputFormat",
"==",
"Dot",
"\n\n",
"locations",
":=",
"make",
"(",
"map",
"[",
"uint64",
"]",
"[",
"]",
"nodeInfo",
")",
"\n",
"for",
"_",
",",
"l",
":=",
"range",
"prof",
".",
"Location",
"{",
"locations",
"[",
"l",
".",
"ID",
"]",
"=",
"newLocInfo",
"(",
"l",
")",
"\n",
"}",
"\n\n",
"nm",
":=",
"make",
"(",
"nodeMap",
")",
"\n",
"for",
"_",
",",
"sample",
":=",
"range",
"prof",
".",
"Sample",
"{",
"if",
"sample",
".",
"Location",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n\n",
"// Construct list of node names for sample.",
"var",
"stack",
"[",
"]",
"nodeInfo",
"\n",
"for",
"_",
",",
"loc",
":=",
"range",
"sample",
".",
"Location",
"{",
"id",
":=",
"loc",
".",
"ID",
"\n",
"stack",
"=",
"append",
"(",
"stack",
",",
"locations",
"[",
"id",
"]",
"...",
")",
"\n",
"}",
"\n\n",
"// Upfront pass to update the parent chains, to prevent the",
"// merging of nodes with different parents.",
"if",
"buildTree",
"{",
"var",
"nn",
"*",
"node",
"\n",
"for",
"i",
":=",
"len",
"(",
"stack",
")",
";",
"i",
">",
"0",
";",
"i",
"--",
"{",
"n",
":=",
"&",
"stack",
"[",
"i",
"-",
"1",
"]",
"\n",
"n",
".",
"parent",
"=",
"nn",
"\n",
"nn",
"=",
"nm",
".",
"findOrInsertNode",
"(",
"*",
"n",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"leaf",
":=",
"nm",
".",
"findOrInsertNode",
"(",
"stack",
"[",
"0",
"]",
")",
"\n",
"weight",
":=",
"rpt",
".",
"sampleValue",
"(",
"sample",
")",
"\n",
"leaf",
".",
"addTags",
"(",
"sample",
",",
"weight",
")",
"\n\n",
"// Aggregate counter data.",
"leaf",
".",
"flat",
"+=",
"weight",
"\n",
"seen",
":=",
"make",
"(",
"map",
"[",
"*",
"node",
"]",
"bool",
")",
"\n",
"var",
"nn",
"*",
"node",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"stack",
"{",
"n",
":=",
"nm",
".",
"findOrInsertNode",
"(",
"s",
")",
"\n",
"if",
"!",
"seen",
"[",
"n",
"]",
"{",
"seen",
"[",
"n",
"]",
"=",
"true",
"\n",
"n",
".",
"cum",
"+=",
"weight",
"\n\n",
"if",
"nn",
"!=",
"nil",
"{",
"bumpWeight",
"(",
"n",
",",
"nn",
",",
"weight",
",",
"false",
")",
"\n",
"}",
"\n",
"}",
"\n",
"nn",
"=",
"n",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Collect new nodes into a report.",
"ns",
":=",
"make",
"(",
"nodes",
",",
"0",
",",
"len",
"(",
"nm",
")",
")",
"\n",
"for",
"_",
",",
"n",
":=",
"range",
"nm",
"{",
"if",
"rpt",
".",
"options",
".",
"DropNegative",
"&&",
"n",
".",
"flat",
"<",
"0",
"{",
"continue",
"\n",
"}",
"\n",
"ns",
"=",
"append",
"(",
"ns",
",",
"n",
")",
"\n",
"}",
"\n\n",
"return",
"graph",
"{",
"ns",
"}",
",",
"nil",
"\n",
"}"
] | // newGraph summarizes performance data from a profile into a graph. | [
"newGraph",
"summarizes",
"performance",
"data",
"from",
"a",
"profile",
"into",
"a",
"graph",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/report/report.go#L1008-L1076 |
1,481 | rakyll/gom | internal/report/report.go | newLocInfo | func newLocInfo(l *profile.Location) []nodeInfo {
var objfile string
if m := l.Mapping; m != nil {
objfile = filepath.Base(m.File)
}
if len(l.Line) == 0 {
return []nodeInfo{
{
address: l.Address,
objfile: objfile,
},
}
}
var info []nodeInfo
numInlineFrames := len(l.Line) - 1
for li, line := range l.Line {
ni := nodeInfo{
address: l.Address,
lineno: int(line.Line),
inline: li < numInlineFrames,
objfile: objfile,
}
if line.Function != nil {
ni.name = line.Function.Name
ni.origName = line.Function.SystemName
ni.file = line.Function.Filename
ni.startLine = int(line.Function.StartLine)
}
info = append(info, ni)
}
return info
} | go | func newLocInfo(l *profile.Location) []nodeInfo {
var objfile string
if m := l.Mapping; m != nil {
objfile = filepath.Base(m.File)
}
if len(l.Line) == 0 {
return []nodeInfo{
{
address: l.Address,
objfile: objfile,
},
}
}
var info []nodeInfo
numInlineFrames := len(l.Line) - 1
for li, line := range l.Line {
ni := nodeInfo{
address: l.Address,
lineno: int(line.Line),
inline: li < numInlineFrames,
objfile: objfile,
}
if line.Function != nil {
ni.name = line.Function.Name
ni.origName = line.Function.SystemName
ni.file = line.Function.Filename
ni.startLine = int(line.Function.StartLine)
}
info = append(info, ni)
}
return info
} | [
"func",
"newLocInfo",
"(",
"l",
"*",
"profile",
".",
"Location",
")",
"[",
"]",
"nodeInfo",
"{",
"var",
"objfile",
"string",
"\n\n",
"if",
"m",
":=",
"l",
".",
"Mapping",
";",
"m",
"!=",
"nil",
"{",
"objfile",
"=",
"filepath",
".",
"Base",
"(",
"m",
".",
"File",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"l",
".",
"Line",
")",
"==",
"0",
"{",
"return",
"[",
"]",
"nodeInfo",
"{",
"{",
"address",
":",
"l",
".",
"Address",
",",
"objfile",
":",
"objfile",
",",
"}",
",",
"}",
"\n",
"}",
"\n",
"var",
"info",
"[",
"]",
"nodeInfo",
"\n",
"numInlineFrames",
":=",
"len",
"(",
"l",
".",
"Line",
")",
"-",
"1",
"\n",
"for",
"li",
",",
"line",
":=",
"range",
"l",
".",
"Line",
"{",
"ni",
":=",
"nodeInfo",
"{",
"address",
":",
"l",
".",
"Address",
",",
"lineno",
":",
"int",
"(",
"line",
".",
"Line",
")",
",",
"inline",
":",
"li",
"<",
"numInlineFrames",
",",
"objfile",
":",
"objfile",
",",
"}",
"\n\n",
"if",
"line",
".",
"Function",
"!=",
"nil",
"{",
"ni",
".",
"name",
"=",
"line",
".",
"Function",
".",
"Name",
"\n",
"ni",
".",
"origName",
"=",
"line",
".",
"Function",
".",
"SystemName",
"\n",
"ni",
".",
"file",
"=",
"line",
".",
"Function",
".",
"Filename",
"\n",
"ni",
".",
"startLine",
"=",
"int",
"(",
"line",
".",
"Function",
".",
"StartLine",
")",
"\n",
"}",
"\n\n",
"info",
"=",
"append",
"(",
"info",
",",
"ni",
")",
"\n",
"}",
"\n",
"return",
"info",
"\n",
"}"
] | // Create a slice of formatted names for a location. | [
"Create",
"a",
"slice",
"of",
"formatted",
"names",
"for",
"a",
"location",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/report/report.go#L1079-L1114 |
1,482 | rakyll/gom | internal/report/report.go | countEdges | func countEdges(el edgeMap, cutoff int64) int {
count := 0
for _, e := range el {
if e.weight > cutoff {
count++
}
}
return count
} | go | func countEdges(el edgeMap, cutoff int64) int {
count := 0
for _, e := range el {
if e.weight > cutoff {
count++
}
}
return count
} | [
"func",
"countEdges",
"(",
"el",
"edgeMap",
",",
"cutoff",
"int64",
")",
"int",
"{",
"count",
":=",
"0",
"\n",
"for",
"_",
",",
"e",
":=",
"range",
"el",
"{",
"if",
"e",
".",
"weight",
">",
"cutoff",
"{",
"count",
"++",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"count",
"\n",
"}"
] | // countEdges counts the number of edges below the specified cutoff. | [
"countEdges",
"counts",
"the",
"number",
"of",
"edges",
"below",
"the",
"specified",
"cutoff",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/report/report.go#L1275-L1283 |
1,483 | rakyll/gom | internal/report/report.go | removeRedundantEdges | func removeRedundantEdges(ns nodes) {
// Walk the nodes and outgoing edges in reverse order to prefer
// removing edges with the lowest weight.
for i := len(ns); i > 0; i-- {
n := ns[i-1]
in := sortedEdges(n.in)
for j := len(in); j > 0; j-- {
if e := in[j-1]; e.residual && isRedundant(e) {
delete(e.src.out, e.dest)
delete(e.dest.in, e.src)
}
}
}
} | go | func removeRedundantEdges(ns nodes) {
// Walk the nodes and outgoing edges in reverse order to prefer
// removing edges with the lowest weight.
for i := len(ns); i > 0; i-- {
n := ns[i-1]
in := sortedEdges(n.in)
for j := len(in); j > 0; j-- {
if e := in[j-1]; e.residual && isRedundant(e) {
delete(e.src.out, e.dest)
delete(e.dest.in, e.src)
}
}
}
} | [
"func",
"removeRedundantEdges",
"(",
"ns",
"nodes",
")",
"{",
"// Walk the nodes and outgoing edges in reverse order to prefer",
"// removing edges with the lowest weight.",
"for",
"i",
":=",
"len",
"(",
"ns",
")",
";",
"i",
">",
"0",
";",
"i",
"--",
"{",
"n",
":=",
"ns",
"[",
"i",
"-",
"1",
"]",
"\n",
"in",
":=",
"sortedEdges",
"(",
"n",
".",
"in",
")",
"\n",
"for",
"j",
":=",
"len",
"(",
"in",
")",
";",
"j",
">",
"0",
";",
"j",
"--",
"{",
"if",
"e",
":=",
"in",
"[",
"j",
"-",
"1",
"]",
";",
"e",
".",
"residual",
"&&",
"isRedundant",
"(",
"e",
")",
"{",
"delete",
"(",
"e",
".",
"src",
".",
"out",
",",
"e",
".",
"dest",
")",
"\n",
"delete",
"(",
"e",
".",
"dest",
".",
"in",
",",
"e",
".",
"src",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // removeRedundantEdges removes residual edges if the destination can
// be reached through another path. This is done to simplify the graph
// while preserving connectivity. | [
"removeRedundantEdges",
"removes",
"residual",
"edges",
"if",
"the",
"destination",
"can",
"be",
"reached",
"through",
"another",
"path",
".",
"This",
"is",
"done",
"to",
"simplify",
"the",
"graph",
"while",
"preserving",
"connectivity",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/report/report.go#L1314-L1327 |
1,484 | rakyll/gom | internal/report/report.go | isRedundant | func isRedundant(e *edgeInfo) bool {
destPred := predecessors(e, e.dest)
if len(destPred) == 1 {
return false
}
srcPred := predecessors(e, e.src)
for n := range srcPred {
if destPred[n] && n != e.dest {
return true
}
}
return false
} | go | func isRedundant(e *edgeInfo) bool {
destPred := predecessors(e, e.dest)
if len(destPred) == 1 {
return false
}
srcPred := predecessors(e, e.src)
for n := range srcPred {
if destPred[n] && n != e.dest {
return true
}
}
return false
} | [
"func",
"isRedundant",
"(",
"e",
"*",
"edgeInfo",
")",
"bool",
"{",
"destPred",
":=",
"predecessors",
"(",
"e",
",",
"e",
".",
"dest",
")",
"\n",
"if",
"len",
"(",
"destPred",
")",
"==",
"1",
"{",
"return",
"false",
"\n",
"}",
"\n",
"srcPred",
":=",
"predecessors",
"(",
"e",
",",
"e",
".",
"src",
")",
"\n\n",
"for",
"n",
":=",
"range",
"srcPred",
"{",
"if",
"destPred",
"[",
"n",
"]",
"&&",
"n",
"!=",
"e",
".",
"dest",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // isRedundant determines if an edge can be removed without impacting
// connectivity of the whole graph. This is implemented by checking if the
// nodes have a common ancestor after removing the edge. | [
"isRedundant",
"determines",
"if",
"an",
"edge",
"can",
"be",
"removed",
"without",
"impacting",
"connectivity",
"of",
"the",
"whole",
"graph",
".",
"This",
"is",
"implemented",
"by",
"checking",
"if",
"the",
"nodes",
"have",
"a",
"common",
"ancestor",
"after",
"removing",
"the",
"edge",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/report/report.go#L1332-L1345 |
1,485 | rakyll/gom | internal/report/report.go | predecessors | func predecessors(e *edgeInfo, n *node) map[*node]bool {
seen := map[*node]bool{n: true}
queue := []*node{n}
for len(queue) > 0 {
n := queue[0]
queue = queue[1:]
for _, ie := range n.in {
if e == ie || seen[ie.src] {
continue
}
seen[ie.src] = true
queue = append(queue, ie.src)
}
}
return seen
} | go | func predecessors(e *edgeInfo, n *node) map[*node]bool {
seen := map[*node]bool{n: true}
queue := []*node{n}
for len(queue) > 0 {
n := queue[0]
queue = queue[1:]
for _, ie := range n.in {
if e == ie || seen[ie.src] {
continue
}
seen[ie.src] = true
queue = append(queue, ie.src)
}
}
return seen
} | [
"func",
"predecessors",
"(",
"e",
"*",
"edgeInfo",
",",
"n",
"*",
"node",
")",
"map",
"[",
"*",
"node",
"]",
"bool",
"{",
"seen",
":=",
"map",
"[",
"*",
"node",
"]",
"bool",
"{",
"n",
":",
"true",
"}",
"\n",
"queue",
":=",
"[",
"]",
"*",
"node",
"{",
"n",
"}",
"\n",
"for",
"len",
"(",
"queue",
")",
">",
"0",
"{",
"n",
":=",
"queue",
"[",
"0",
"]",
"\n",
"queue",
"=",
"queue",
"[",
"1",
":",
"]",
"\n",
"for",
"_",
",",
"ie",
":=",
"range",
"n",
".",
"in",
"{",
"if",
"e",
"==",
"ie",
"||",
"seen",
"[",
"ie",
".",
"src",
"]",
"{",
"continue",
"\n",
"}",
"\n",
"seen",
"[",
"ie",
".",
"src",
"]",
"=",
"true",
"\n",
"queue",
"=",
"append",
"(",
"queue",
",",
"ie",
".",
"src",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"seen",
"\n",
"}"
] | // predecessors collects all the predecessors to node n, excluding edge e. | [
"predecessors",
"collects",
"all",
"the",
"predecessors",
"to",
"node",
"n",
"excluding",
"edge",
"e",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/report/report.go#L1348-L1363 |
1,486 | rakyll/gom | internal/report/report.go | ScaleValue | func ScaleValue(value int64, fromUnit, toUnit string) (sv float64, su string) {
// Avoid infinite recursion on overflow.
if value < 0 && -value > 0 {
v, u := ScaleValue(-value, fromUnit, toUnit)
return -v, u
}
if m, u, ok := memoryLabel(value, fromUnit, toUnit); ok {
return m, u
}
if t, u, ok := timeLabel(value, fromUnit, toUnit); ok {
return t, u
}
// Skip non-interesting units.
switch toUnit {
case "count", "sample", "unit", "minimum":
return float64(value), ""
default:
return float64(value), toUnit
}
} | go | func ScaleValue(value int64, fromUnit, toUnit string) (sv float64, su string) {
// Avoid infinite recursion on overflow.
if value < 0 && -value > 0 {
v, u := ScaleValue(-value, fromUnit, toUnit)
return -v, u
}
if m, u, ok := memoryLabel(value, fromUnit, toUnit); ok {
return m, u
}
if t, u, ok := timeLabel(value, fromUnit, toUnit); ok {
return t, u
}
// Skip non-interesting units.
switch toUnit {
case "count", "sample", "unit", "minimum":
return float64(value), ""
default:
return float64(value), toUnit
}
} | [
"func",
"ScaleValue",
"(",
"value",
"int64",
",",
"fromUnit",
",",
"toUnit",
"string",
")",
"(",
"sv",
"float64",
",",
"su",
"string",
")",
"{",
"// Avoid infinite recursion on overflow.",
"if",
"value",
"<",
"0",
"&&",
"-",
"value",
">",
"0",
"{",
"v",
",",
"u",
":=",
"ScaleValue",
"(",
"-",
"value",
",",
"fromUnit",
",",
"toUnit",
")",
"\n",
"return",
"-",
"v",
",",
"u",
"\n",
"}",
"\n",
"if",
"m",
",",
"u",
",",
"ok",
":=",
"memoryLabel",
"(",
"value",
",",
"fromUnit",
",",
"toUnit",
")",
";",
"ok",
"{",
"return",
"m",
",",
"u",
"\n",
"}",
"\n",
"if",
"t",
",",
"u",
",",
"ok",
":=",
"timeLabel",
"(",
"value",
",",
"fromUnit",
",",
"toUnit",
")",
";",
"ok",
"{",
"return",
"t",
",",
"u",
"\n",
"}",
"\n",
"// Skip non-interesting units.",
"switch",
"toUnit",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
":",
"return",
"float64",
"(",
"value",
")",
",",
"\"",
"\"",
"\n",
"default",
":",
"return",
"float64",
"(",
"value",
")",
",",
"toUnit",
"\n",
"}",
"\n",
"}"
] | // ScaleValue reformats a value from a unit to a different unit. | [
"ScaleValue",
"reformats",
"a",
"value",
"from",
"a",
"unit",
"to",
"a",
"different",
"unit",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/report/report.go#L1510-L1529 |
1,487 | rakyll/gom | internal/report/report.go | prettyName | func (info *nodeInfo) prettyName() string {
var name string
if info.address != 0 {
name = fmt.Sprintf("%016x", info.address)
}
if info.name != "" {
name = name + " " + info.name
}
if info.file != "" {
name += " " + trimPath(info.file)
if info.lineno != 0 {
name += fmt.Sprintf(":%d", info.lineno)
}
}
if info.inline {
name = name + " (inline)"
}
if name = strings.TrimSpace(name); name == "" && info.objfile != "" {
name = "[" + info.objfile + "]"
}
return name
} | go | func (info *nodeInfo) prettyName() string {
var name string
if info.address != 0 {
name = fmt.Sprintf("%016x", info.address)
}
if info.name != "" {
name = name + " " + info.name
}
if info.file != "" {
name += " " + trimPath(info.file)
if info.lineno != 0 {
name += fmt.Sprintf(":%d", info.lineno)
}
}
if info.inline {
name = name + " (inline)"
}
if name = strings.TrimSpace(name); name == "" && info.objfile != "" {
name = "[" + info.objfile + "]"
}
return name
} | [
"func",
"(",
"info",
"*",
"nodeInfo",
")",
"prettyName",
"(",
")",
"string",
"{",
"var",
"name",
"string",
"\n",
"if",
"info",
".",
"address",
"!=",
"0",
"{",
"name",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"info",
".",
"address",
")",
"\n",
"}",
"\n\n",
"if",
"info",
".",
"name",
"!=",
"\"",
"\"",
"{",
"name",
"=",
"name",
"+",
"\"",
"\"",
"+",
"info",
".",
"name",
"\n",
"}",
"\n\n",
"if",
"info",
".",
"file",
"!=",
"\"",
"\"",
"{",
"name",
"+=",
"\"",
"\"",
"+",
"trimPath",
"(",
"info",
".",
"file",
")",
"\n",
"if",
"info",
".",
"lineno",
"!=",
"0",
"{",
"name",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"info",
".",
"lineno",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"info",
".",
"inline",
"{",
"name",
"=",
"name",
"+",
"\"",
"\"",
"\n",
"}",
"\n\n",
"if",
"name",
"=",
"strings",
".",
"TrimSpace",
"(",
"name",
")",
";",
"name",
"==",
"\"",
"\"",
"&&",
"info",
".",
"objfile",
"!=",
"\"",
"\"",
"{",
"name",
"=",
"\"",
"\"",
"+",
"info",
".",
"objfile",
"+",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"name",
"\n",
"}"
] | // prettyName determines the printable name to be used for a node. | [
"prettyName",
"determines",
"the",
"printable",
"name",
"to",
"be",
"used",
"for",
"a",
"node",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/report/report.go#L1662-L1687 |
1,488 | rakyll/gom | internal/report/report.go | NewDefault | func NewDefault(prof *profile.Profile, options Options) *Report {
index := len(prof.SampleType) - 1
o := &options
if o.SampleUnit == "" {
o.SampleUnit = strings.ToLower(prof.SampleType[index].Unit)
}
value := func(s *profile.Sample) int64 {
return s.Value[index]
}
format := func(v int64) string {
if r := o.Ratio; r > 0 && r != 1 {
fv := float64(v) * r
v = int64(fv)
}
return scaledValueLabel(v, o.SampleUnit, o.OutputUnit)
}
return &Report{prof, computeTotal(prof, value), o, value, format}
} | go | func NewDefault(prof *profile.Profile, options Options) *Report {
index := len(prof.SampleType) - 1
o := &options
if o.SampleUnit == "" {
o.SampleUnit = strings.ToLower(prof.SampleType[index].Unit)
}
value := func(s *profile.Sample) int64 {
return s.Value[index]
}
format := func(v int64) string {
if r := o.Ratio; r > 0 && r != 1 {
fv := float64(v) * r
v = int64(fv)
}
return scaledValueLabel(v, o.SampleUnit, o.OutputUnit)
}
return &Report{prof, computeTotal(prof, value), o, value, format}
} | [
"func",
"NewDefault",
"(",
"prof",
"*",
"profile",
".",
"Profile",
",",
"options",
"Options",
")",
"*",
"Report",
"{",
"index",
":=",
"len",
"(",
"prof",
".",
"SampleType",
")",
"-",
"1",
"\n",
"o",
":=",
"&",
"options",
"\n",
"if",
"o",
".",
"SampleUnit",
"==",
"\"",
"\"",
"{",
"o",
".",
"SampleUnit",
"=",
"strings",
".",
"ToLower",
"(",
"prof",
".",
"SampleType",
"[",
"index",
"]",
".",
"Unit",
")",
"\n",
"}",
"\n",
"value",
":=",
"func",
"(",
"s",
"*",
"profile",
".",
"Sample",
")",
"int64",
"{",
"return",
"s",
".",
"Value",
"[",
"index",
"]",
"\n",
"}",
"\n",
"format",
":=",
"func",
"(",
"v",
"int64",
")",
"string",
"{",
"if",
"r",
":=",
"o",
".",
"Ratio",
";",
"r",
">",
"0",
"&&",
"r",
"!=",
"1",
"{",
"fv",
":=",
"float64",
"(",
"v",
")",
"*",
"r",
"\n",
"v",
"=",
"int64",
"(",
"fv",
")",
"\n",
"}",
"\n",
"return",
"scaledValueLabel",
"(",
"v",
",",
"o",
".",
"SampleUnit",
",",
"o",
".",
"OutputUnit",
")",
"\n",
"}",
"\n",
"return",
"&",
"Report",
"{",
"prof",
",",
"computeTotal",
"(",
"prof",
",",
"value",
")",
",",
"o",
",",
"value",
",",
"format",
"}",
"\n",
"}"
] | // NewDefault builds a new report indexing the sample values with the
// last value available. | [
"NewDefault",
"builds",
"a",
"new",
"report",
"indexing",
"the",
"sample",
"values",
"with",
"the",
"last",
"value",
"available",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/report/report.go#L1708-L1725 |
1,489 | rakyll/gom | internal/commands/commands.go | NewCompleter | func NewCompleter(cs Commands) Completer {
return func(line string) string {
switch tokens := strings.Fields(line); len(tokens) {
case 0:
// Nothing to complete
case 1:
// Single token -- complete command name
found := ""
for c := range cs {
if strings.HasPrefix(c, tokens[0]) {
if found != "" {
return line
}
found = c
}
}
if found != "" {
return found
}
default:
// Multiple tokens -- complete using command completer
if c, ok := cs[tokens[0]]; ok {
if c.Complete != nil {
lastTokenIdx := len(tokens) - 1
lastToken := tokens[lastTokenIdx]
if strings.HasPrefix(lastToken, "-") {
lastToken = "-" + c.Complete(lastToken[1:])
} else {
lastToken = c.Complete(lastToken)
}
return strings.Join(append(tokens[:lastTokenIdx], lastToken), " ")
}
}
}
return line
}
} | go | func NewCompleter(cs Commands) Completer {
return func(line string) string {
switch tokens := strings.Fields(line); len(tokens) {
case 0:
// Nothing to complete
case 1:
// Single token -- complete command name
found := ""
for c := range cs {
if strings.HasPrefix(c, tokens[0]) {
if found != "" {
return line
}
found = c
}
}
if found != "" {
return found
}
default:
// Multiple tokens -- complete using command completer
if c, ok := cs[tokens[0]]; ok {
if c.Complete != nil {
lastTokenIdx := len(tokens) - 1
lastToken := tokens[lastTokenIdx]
if strings.HasPrefix(lastToken, "-") {
lastToken = "-" + c.Complete(lastToken[1:])
} else {
lastToken = c.Complete(lastToken)
}
return strings.Join(append(tokens[:lastTokenIdx], lastToken), " ")
}
}
}
return line
}
} | [
"func",
"NewCompleter",
"(",
"cs",
"Commands",
")",
"Completer",
"{",
"return",
"func",
"(",
"line",
"string",
")",
"string",
"{",
"switch",
"tokens",
":=",
"strings",
".",
"Fields",
"(",
"line",
")",
";",
"len",
"(",
"tokens",
")",
"{",
"case",
"0",
":",
"// Nothing to complete",
"case",
"1",
":",
"// Single token -- complete command name",
"found",
":=",
"\"",
"\"",
"\n",
"for",
"c",
":=",
"range",
"cs",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"c",
",",
"tokens",
"[",
"0",
"]",
")",
"{",
"if",
"found",
"!=",
"\"",
"\"",
"{",
"return",
"line",
"\n",
"}",
"\n",
"found",
"=",
"c",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"found",
"!=",
"\"",
"\"",
"{",
"return",
"found",
"\n",
"}",
"\n",
"default",
":",
"// Multiple tokens -- complete using command completer",
"if",
"c",
",",
"ok",
":=",
"cs",
"[",
"tokens",
"[",
"0",
"]",
"]",
";",
"ok",
"{",
"if",
"c",
".",
"Complete",
"!=",
"nil",
"{",
"lastTokenIdx",
":=",
"len",
"(",
"tokens",
")",
"-",
"1",
"\n",
"lastToken",
":=",
"tokens",
"[",
"lastTokenIdx",
"]",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"lastToken",
",",
"\"",
"\"",
")",
"{",
"lastToken",
"=",
"\"",
"\"",
"+",
"c",
".",
"Complete",
"(",
"lastToken",
"[",
"1",
":",
"]",
")",
"\n",
"}",
"else",
"{",
"lastToken",
"=",
"c",
".",
"Complete",
"(",
"lastToken",
")",
"\n",
"}",
"\n",
"return",
"strings",
".",
"Join",
"(",
"append",
"(",
"tokens",
"[",
":",
"lastTokenIdx",
"]",
",",
"lastToken",
")",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"line",
"\n",
"}",
"\n",
"}"
] | // NewCompleter creates an autocompletion function for a set of commands. | [
"NewCompleter",
"creates",
"an",
"autocompletion",
"function",
"for",
"a",
"set",
"of",
"commands",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/commands/commands.go#L104-L140 |
1,490 | rakyll/gom | internal/fetch/fetch.go | Fetcher | func Fetcher(source string, timeout time.Duration, ui plugin.UI) (*profile.Profile, error) {
var f io.ReadCloser
var err error
url, err := url.Parse(source)
if err == nil && url.Host != "" {
f, err = FetchURL(source, timeout)
} else {
f, err = os.Open(source)
}
if err != nil {
return nil, err
}
defer f.Close()
return profile.Parse(f)
} | go | func Fetcher(source string, timeout time.Duration, ui plugin.UI) (*profile.Profile, error) {
var f io.ReadCloser
var err error
url, err := url.Parse(source)
if err == nil && url.Host != "" {
f, err = FetchURL(source, timeout)
} else {
f, err = os.Open(source)
}
if err != nil {
return nil, err
}
defer f.Close()
return profile.Parse(f)
} | [
"func",
"Fetcher",
"(",
"source",
"string",
",",
"timeout",
"time",
".",
"Duration",
",",
"ui",
"plugin",
".",
"UI",
")",
"(",
"*",
"profile",
".",
"Profile",
",",
"error",
")",
"{",
"var",
"f",
"io",
".",
"ReadCloser",
"\n",
"var",
"err",
"error",
"\n\n",
"url",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"source",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"url",
".",
"Host",
"!=",
"\"",
"\"",
"{",
"f",
",",
"err",
"=",
"FetchURL",
"(",
"source",
",",
"timeout",
")",
"\n",
"}",
"else",
"{",
"f",
",",
"err",
"=",
"os",
".",
"Open",
"(",
"source",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n",
"return",
"profile",
".",
"Parse",
"(",
"f",
")",
"\n",
"}"
] | // Fetcher is the plugin.Fetcher version of FetchProfile. | [
"Fetcher",
"is",
"the",
"plugin",
".",
"Fetcher",
"version",
"of",
"FetchProfile",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/fetch/fetch.go#L30-L45 |
1,491 | rakyll/gom | internal/fetch/fetch.go | FetchURL | func FetchURL(source string, timeout time.Duration) (io.ReadCloser, error) {
resp, err := httpGet(source, timeout)
if err != nil {
return nil, fmt.Errorf("http fetch %s: %v", source, err)
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("server response: %s", resp.Status)
}
return resp.Body, nil
} | go | func FetchURL(source string, timeout time.Duration) (io.ReadCloser, error) {
resp, err := httpGet(source, timeout)
if err != nil {
return nil, fmt.Errorf("http fetch %s: %v", source, err)
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("server response: %s", resp.Status)
}
return resp.Body, nil
} | [
"func",
"FetchURL",
"(",
"source",
"string",
",",
"timeout",
"time",
".",
"Duration",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"resp",
",",
"err",
":=",
"httpGet",
"(",
"source",
",",
"timeout",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"source",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"http",
".",
"StatusOK",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"resp",
".",
"Status",
")",
"\n",
"}",
"\n\n",
"return",
"resp",
".",
"Body",
",",
"nil",
"\n",
"}"
] | // FetchURL fetches a profile from a URL using HTTP. | [
"FetchURL",
"fetches",
"a",
"profile",
"from",
"a",
"URL",
"using",
"HTTP",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/fetch/fetch.go#L48-L58 |
1,492 | rakyll/gom | internal/fetch/fetch.go | PostURL | func PostURL(source, post string) ([]byte, error) {
resp, err := http.Post(source, "application/octet-stream", strings.NewReader(post))
if err != nil {
return nil, fmt.Errorf("http post %s: %v", source, err)
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("server response: %s", resp.Status)
}
defer resp.Body.Close()
return ioutil.ReadAll(resp.Body)
} | go | func PostURL(source, post string) ([]byte, error) {
resp, err := http.Post(source, "application/octet-stream", strings.NewReader(post))
if err != nil {
return nil, fmt.Errorf("http post %s: %v", source, err)
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("server response: %s", resp.Status)
}
defer resp.Body.Close()
return ioutil.ReadAll(resp.Body)
} | [
"func",
"PostURL",
"(",
"source",
",",
"post",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"resp",
",",
"err",
":=",
"http",
".",
"Post",
"(",
"source",
",",
"\"",
"\"",
",",
"strings",
".",
"NewReader",
"(",
"post",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"source",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"http",
".",
"StatusOK",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"resp",
".",
"Status",
")",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"return",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"}"
] | // PostURL issues a POST to a URL over HTTP. | [
"PostURL",
"issues",
"a",
"POST",
"to",
"a",
"URL",
"over",
"HTTP",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/fetch/fetch.go#L61-L71 |
1,493 | rakyll/gom | cmd/gom/report.go | fetch | func (r *report) fetch(force bool, secs time.Duration) error {
r.mu.Lock()
defer r.mu.Unlock()
if r.p != nil && !force {
return nil
}
if secs == 0 {
secs = 60 * time.Second
}
url := fmt.Sprintf("%s/debug/_gom?view=profile&name=%s", *target, r.name)
p, err := fetch.FetchProfile(url, secs)
if err != nil {
return err
}
if err := symbolz.Symbolize(fmt.Sprintf("%s/debug/_gom?view=symbol", *target), fetch.PostURL, p); err != nil {
return err
}
r.p = p
return nil
} | go | func (r *report) fetch(force bool, secs time.Duration) error {
r.mu.Lock()
defer r.mu.Unlock()
if r.p != nil && !force {
return nil
}
if secs == 0 {
secs = 60 * time.Second
}
url := fmt.Sprintf("%s/debug/_gom?view=profile&name=%s", *target, r.name)
p, err := fetch.FetchProfile(url, secs)
if err != nil {
return err
}
if err := symbolz.Symbolize(fmt.Sprintf("%s/debug/_gom?view=symbol", *target), fetch.PostURL, p); err != nil {
return err
}
r.p = p
return nil
} | [
"func",
"(",
"r",
"*",
"report",
")",
"fetch",
"(",
"force",
"bool",
",",
"secs",
"time",
".",
"Duration",
")",
"error",
"{",
"r",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"r",
".",
"p",
"!=",
"nil",
"&&",
"!",
"force",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"secs",
"==",
"0",
"{",
"secs",
"=",
"60",
"*",
"time",
".",
"Second",
"\n",
"}",
"\n",
"url",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"*",
"target",
",",
"r",
".",
"name",
")",
"\n",
"p",
",",
"err",
":=",
"fetch",
".",
"FetchProfile",
"(",
"url",
",",
"secs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"symbolz",
".",
"Symbolize",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"*",
"target",
")",
",",
"fetch",
".",
"PostURL",
",",
"p",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"r",
".",
"p",
"=",
"p",
"\n",
"return",
"nil",
"\n",
"}"
] | // fetch fetches the current profile and the symbols from the target program. | [
"fetch",
"fetches",
"the",
"current",
"profile",
"and",
"the",
"symbols",
"from",
"the",
"target",
"program",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/cmd/gom/report.go#L39-L58 |
1,494 | rakyll/gom | cmd/gom/report.go | filter | func (r *report) filter(cum bool, focus *regexp.Regexp) []string {
r.mu.Lock()
defer r.mu.Unlock()
if r.p == nil {
return nil
}
c := r.p.Copy()
c.FilterSamplesByName(focus, nil, nil)
rpt := goreport.NewDefault(c, goreport.Options{
OutputFormat: goreport.Text,
CumSort: cum,
PrintAddresses: true,
})
buf := bytes.NewBuffer(nil)
goreport.Generate(buf, rpt, nil)
return strings.Split(buf.String(), "\n")
} | go | func (r *report) filter(cum bool, focus *regexp.Regexp) []string {
r.mu.Lock()
defer r.mu.Unlock()
if r.p == nil {
return nil
}
c := r.p.Copy()
c.FilterSamplesByName(focus, nil, nil)
rpt := goreport.NewDefault(c, goreport.Options{
OutputFormat: goreport.Text,
CumSort: cum,
PrintAddresses: true,
})
buf := bytes.NewBuffer(nil)
goreport.Generate(buf, rpt, nil)
return strings.Split(buf.String(), "\n")
} | [
"func",
"(",
"r",
"*",
"report",
")",
"filter",
"(",
"cum",
"bool",
",",
"focus",
"*",
"regexp",
".",
"Regexp",
")",
"[",
"]",
"string",
"{",
"r",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"r",
".",
"p",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"c",
":=",
"r",
".",
"p",
".",
"Copy",
"(",
")",
"\n",
"c",
".",
"FilterSamplesByName",
"(",
"focus",
",",
"nil",
",",
"nil",
")",
"\n",
"rpt",
":=",
"goreport",
".",
"NewDefault",
"(",
"c",
",",
"goreport",
".",
"Options",
"{",
"OutputFormat",
":",
"goreport",
".",
"Text",
",",
"CumSort",
":",
"cum",
",",
"PrintAddresses",
":",
"true",
",",
"}",
")",
"\n",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"nil",
")",
"\n",
"goreport",
".",
"Generate",
"(",
"buf",
",",
"rpt",
",",
"nil",
")",
"\n",
"return",
"strings",
".",
"Split",
"(",
"buf",
".",
"String",
"(",
")",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"}"
] | // filter filters the report with a focus regex. If no focus is provided,
// it reports back with the entire set of calls.
// Focus regex works on the package, type and function names. Filtered
// results will include parent samples from the call graph. | [
"filter",
"filters",
"the",
"report",
"with",
"a",
"focus",
"regex",
".",
"If",
"no",
"focus",
"is",
"provided",
"it",
"reports",
"back",
"with",
"the",
"entire",
"set",
"of",
"calls",
".",
"Focus",
"regex",
"works",
"on",
"the",
"package",
"type",
"and",
"function",
"names",
".",
"Filtered",
"results",
"will",
"include",
"parent",
"samples",
"from",
"the",
"call",
"graph",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/cmd/gom/report.go#L64-L80 |
1,495 | rakyll/gom | internal/driver/interactive.go | functionCompleter | func functionCompleter(substring string) string {
found := ""
for _, fName := range profileFunctionNames {
if strings.Contains(fName, substring) {
if found != "" {
return substring
}
found = fName
}
}
if found != "" {
return found
}
return substring
} | go | func functionCompleter(substring string) string {
found := ""
for _, fName := range profileFunctionNames {
if strings.Contains(fName, substring) {
if found != "" {
return substring
}
found = fName
}
}
if found != "" {
return found
}
return substring
} | [
"func",
"functionCompleter",
"(",
"substring",
"string",
")",
"string",
"{",
"found",
":=",
"\"",
"\"",
"\n",
"for",
"_",
",",
"fName",
":=",
"range",
"profileFunctionNames",
"{",
"if",
"strings",
".",
"Contains",
"(",
"fName",
",",
"substring",
")",
"{",
"if",
"found",
"!=",
"\"",
"\"",
"{",
"return",
"substring",
"\n",
"}",
"\n",
"found",
"=",
"fName",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"found",
"!=",
"\"",
"\"",
"{",
"return",
"found",
"\n",
"}",
"\n",
"return",
"substring",
"\n",
"}"
] | // functionCompleter replaces provided substring with a function
// name retrieved from a profile if a single match exists. Otherwise,
// it returns unchanged substring. It defaults to no-op if the profile
// is not specified. | [
"functionCompleter",
"replaces",
"provided",
"substring",
"with",
"a",
"function",
"name",
"retrieved",
"from",
"a",
"profile",
"if",
"a",
"single",
"match",
"exists",
".",
"Otherwise",
"it",
"returns",
"unchanged",
"substring",
".",
"It",
"defaults",
"to",
"no",
"-",
"op",
"if",
"the",
"profile",
"is",
"not",
"specified",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/driver/interactive.go#L26-L40 |
1,496 | rakyll/gom | internal/driver/interactive.go | updateAutoComplete | func updateAutoComplete(p *profile.Profile) {
profileFunctionNames = nil // remove function names retrieved previously
for _, fn := range p.Function {
profileFunctionNames = append(profileFunctionNames, fn.Name)
}
} | go | func updateAutoComplete(p *profile.Profile) {
profileFunctionNames = nil // remove function names retrieved previously
for _, fn := range p.Function {
profileFunctionNames = append(profileFunctionNames, fn.Name)
}
} | [
"func",
"updateAutoComplete",
"(",
"p",
"*",
"profile",
".",
"Profile",
")",
"{",
"profileFunctionNames",
"=",
"nil",
"// remove function names retrieved previously",
"\n",
"for",
"_",
",",
"fn",
":=",
"range",
"p",
".",
"Function",
"{",
"profileFunctionNames",
"=",
"append",
"(",
"profileFunctionNames",
",",
"fn",
".",
"Name",
")",
"\n",
"}",
"\n",
"}"
] | // updateAutoComplete enhances autocompletion with information that can be
// retrieved from the profile | [
"updateAutoComplete",
"enhances",
"autocompletion",
"with",
"information",
"that",
"can",
"be",
"retrieved",
"from",
"the",
"profile"
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/driver/interactive.go#L44-L49 |
1,497 | rakyll/gom | internal/driver/interactive.go | validateRegex | func validateRegex(v string) error {
_, err := regexp.Compile(v)
return err
} | go | func validateRegex(v string) error {
_, err := regexp.Compile(v)
return err
} | [
"func",
"validateRegex",
"(",
"v",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"regexp",
".",
"Compile",
"(",
"v",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // validateRegex checks if a string is a valid regular expression. | [
"validateRegex",
"checks",
"if",
"a",
"string",
"is",
"a",
"valid",
"regular",
"expression",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/driver/interactive.go#L137-L140 |
1,498 | rakyll/gom | internal/driver/interactive.go | readCommand | func readCommand(p *profile.Profile, ui plugin.UI, f *flags) (string, error) {
//ui.Print("Options:\n", f.String(p))
s, err := ui.ReadLine()
return strings.TrimSpace(s), err
} | go | func readCommand(p *profile.Profile, ui plugin.UI, f *flags) (string, error) {
//ui.Print("Options:\n", f.String(p))
s, err := ui.ReadLine()
return strings.TrimSpace(s), err
} | [
"func",
"readCommand",
"(",
"p",
"*",
"profile",
".",
"Profile",
",",
"ui",
"plugin",
".",
"UI",
",",
"f",
"*",
"flags",
")",
"(",
"string",
",",
"error",
")",
"{",
"//ui.Print(\"Options:\\n\", f.String(p))",
"s",
",",
"err",
":=",
"ui",
".",
"ReadLine",
"(",
")",
"\n",
"return",
"strings",
".",
"TrimSpace",
"(",
"s",
")",
",",
"err",
"\n",
"}"
] | // readCommand prompts for and reads the next command. | [
"readCommand",
"prompts",
"for",
"and",
"reads",
"the",
"next",
"command",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/driver/interactive.go#L143-L147 |
1,499 | rakyll/gom | internal/driver/interactive.go | parseBool | func parseBool(v string) (bool, error) {
switch strings.ToLower(v) {
case "true", "t", "yes", "y", "1", "":
return true, nil
case "false", "f", "no", "n", "0":
return false, nil
}
return false, fmt.Errorf(`illegal input "%s" for bool value`, v)
} | go | func parseBool(v string) (bool, error) {
switch strings.ToLower(v) {
case "true", "t", "yes", "y", "1", "":
return true, nil
case "false", "f", "no", "n", "0":
return false, nil
}
return false, fmt.Errorf(`illegal input "%s" for bool value`, v)
} | [
"func",
"parseBool",
"(",
"v",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"switch",
"strings",
".",
"ToLower",
"(",
"v",
")",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
":",
"return",
"true",
",",
"nil",
"\n",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
":",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"`illegal input \"%s\" for bool value`",
",",
"v",
")",
"\n",
"}"
] | // parseBool parses a string as a boolean value. | [
"parseBool",
"parses",
"a",
"string",
"as",
"a",
"boolean",
"value",
"."
] | 183a9e70f4777aa03d377d21a0ed023a6afac141 | https://github.com/rakyll/gom/blob/183a9e70f4777aa03d377d21a0ed023a6afac141/internal/driver/interactive.go#L449-L457 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.