id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
14,900
kataras/golog
logger.go
Log
func (l *Logger) Log(level Level, v ...interface{}) { l.print(level, fmt.Sprint(v...), l.NewLine) }
go
func (l *Logger) Log(level Level, v ...interface{}) { l.print(level, fmt.Sprint(v...), l.NewLine) }
[ "func", "(", "l", "*", "Logger", ")", "Log", "(", "level", "Level", ",", "v", "...", "interface", "{", "}", ")", "{", "l", ".", "print", "(", "level", ",", "fmt", ".", "Sprint", "(", "v", "...", ")", ",", "l", ".", "NewLine", ")", "\n", "}" ]
// Log prints a leveled log message to the output. // This method can be used to use custom log levels if needed. // It adds a new line in the end.
[ "Log", "prints", "a", "leveled", "log", "message", "to", "the", "output", ".", "This", "method", "can", "be", "used", "to", "use", "custom", "log", "levels", "if", "needed", ".", "It", "adds", "a", "new", "line", "in", "the", "end", "." ]
03be101463868edc5a81f094fc68a5f6c1b5503a
https://github.com/kataras/golog/blob/03be101463868edc5a81f094fc68a5f6c1b5503a/logger.go#L237-L239
14,901
kataras/golog
logger.go
Errorf
func (l *Logger) Errorf(format string, args ...interface{}) { msg := fmt.Sprintf(format, args...) l.Error(msg) }
go
func (l *Logger) Errorf(format string, args ...interface{}) { msg := fmt.Sprintf(format, args...) l.Error(msg) }
[ "func", "(", "l", "*", "Logger", ")", "Errorf", "(", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", "format", ",", "args", "...", ")", "\n", "l", ".", "Error", "(", "msg", ")", ...
// Errorf will print only when logger's Level is error, warn, info or debug.
[ "Errorf", "will", "print", "only", "when", "logger", "s", "Level", "is", "error", "warn", "info", "or", "debug", "." ]
03be101463868edc5a81f094fc68a5f6c1b5503a
https://github.com/kataras/golog/blob/03be101463868edc5a81f094fc68a5f6c1b5503a/logger.go#L270-L273
14,902
kataras/golog
logger.go
Warnf
func (l *Logger) Warnf(format string, args ...interface{}) { msg := fmt.Sprintf(format, args...) l.Warn(msg) }
go
func (l *Logger) Warnf(format string, args ...interface{}) { msg := fmt.Sprintf(format, args...) l.Warn(msg) }
[ "func", "(", "l", "*", "Logger", ")", "Warnf", "(", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", "format", ",", "args", "...", ")", "\n", "l", ".", "Warn", "(", "msg", ")", "\...
// Warnf will print when logger's Level is warn, info or debug.
[ "Warnf", "will", "print", "when", "logger", "s", "Level", "is", "warn", "info", "or", "debug", "." ]
03be101463868edc5a81f094fc68a5f6c1b5503a
https://github.com/kataras/golog/blob/03be101463868edc5a81f094fc68a5f6c1b5503a/logger.go#L281-L284
14,903
kataras/golog
logger.go
Infof
func (l *Logger) Infof(format string, args ...interface{}) { msg := fmt.Sprintf(format, args...) l.Info(msg) }
go
func (l *Logger) Infof(format string, args ...interface{}) { msg := fmt.Sprintf(format, args...) l.Info(msg) }
[ "func", "(", "l", "*", "Logger", ")", "Infof", "(", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", "format", ",", "args", "...", ")", "\n", "l", ".", "Info", "(", "msg", ")", "\...
// Infof will print when logger's Level is info or debug.
[ "Infof", "will", "print", "when", "logger", "s", "Level", "is", "info", "or", "debug", "." ]
03be101463868edc5a81f094fc68a5f6c1b5503a
https://github.com/kataras/golog/blob/03be101463868edc5a81f094fc68a5f6c1b5503a/logger.go#L292-L295
14,904
kataras/golog
logger.go
Debugf
func (l *Logger) Debugf(format string, args ...interface{}) { // On debug mode don't even try to fmt.Sprintf if it's not required, // this can be used to allow `Debugf` to be called without even the `fmt.Sprintf`'s // performance cost if the logger doesn't allow debug logging. if l.Level >= DebugLevel { msg := fmt.Sprintf(format, args...) l.Debug(msg) } }
go
func (l *Logger) Debugf(format string, args ...interface{}) { // On debug mode don't even try to fmt.Sprintf if it's not required, // this can be used to allow `Debugf` to be called without even the `fmt.Sprintf`'s // performance cost if the logger doesn't allow debug logging. if l.Level >= DebugLevel { msg := fmt.Sprintf(format, args...) l.Debug(msg) } }
[ "func", "(", "l", "*", "Logger", ")", "Debugf", "(", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "// On debug mode don't even try to fmt.Sprintf if it's not required,", "// this can be used to allow `Debugf` to be called without even the `fmt.Sprint...
// Debugf will print when logger's Level is debug.
[ "Debugf", "will", "print", "when", "logger", "s", "Level", "is", "debug", "." ]
03be101463868edc5a81f094fc68a5f6c1b5503a
https://github.com/kataras/golog/blob/03be101463868edc5a81f094fc68a5f6c1b5503a/logger.go#L303-L311
14,905
kataras/golog
logger.go
Handle
func (l *Logger) Handle(handler Handler) { l.mu.Lock() l.handlers = append(l.handlers, handler) l.mu.Unlock() }
go
func (l *Logger) Handle(handler Handler) { l.mu.Lock() l.handlers = append(l.handlers, handler) l.mu.Unlock() }
[ "func", "(", "l", "*", "Logger", ")", "Handle", "(", "handler", "Handler", ")", "{", "l", ".", "mu", ".", "Lock", "(", ")", "\n", "l", ".", "handlers", "=", "append", "(", "l", ".", "handlers", ",", "handler", ")", "\n", "l", ".", "mu", ".", ...
// Handle adds a log handler. // // Handlers can be used to intercept the message between a log value // and the actual print operation, it's called // when one of the print functions called. // If it's return value is true then it means that the specific // handler handled the log by itself therefore no need to // proceed with the default behavior of printing the log // to the specified logger's output. // // It stops on the handler which returns true firstly. // The `Log` value holds the level of the print operation as well.
[ "Handle", "adds", "a", "log", "handler", ".", "Handlers", "can", "be", "used", "to", "intercept", "the", "message", "between", "a", "log", "value", "and", "the", "actual", "print", "operation", "it", "s", "called", "when", "one", "of", "the", "print", "f...
03be101463868edc5a81f094fc68a5f6c1b5503a
https://github.com/kataras/golog/blob/03be101463868edc5a81f094fc68a5f6c1b5503a/logger.go#L356-L360
14,906
kataras/golog
logger.go
Hijack
func (l *Logger) Hijack(hijacker func(ctx *pio.Ctx)) { l.Printer.Hijack(hijacker) }
go
func (l *Logger) Hijack(hijacker func(ctx *pio.Ctx)) { l.Printer.Hijack(hijacker) }
[ "func", "(", "l", "*", "Logger", ")", "Hijack", "(", "hijacker", "func", "(", "ctx", "*", "pio", ".", "Ctx", ")", ")", "{", "l", ".", "Printer", ".", "Hijack", "(", "hijacker", ")", "\n", "}" ]
// Hijack adds a hijacker to the low-level logger's Printer. // If you need to implement such as a low-level hijacker manually, // then you have to make use of the pio library.
[ "Hijack", "adds", "a", "hijacker", "to", "the", "low", "-", "level", "logger", "s", "Printer", ".", "If", "you", "need", "to", "implement", "such", "as", "a", "low", "-", "level", "hijacker", "manually", "then", "you", "have", "to", "make", "use", "of"...
03be101463868edc5a81f094fc68a5f6c1b5503a
https://github.com/kataras/golog/blob/03be101463868edc5a81f094fc68a5f6c1b5503a/logger.go#L374-L376
14,907
kataras/golog
logger.go
Scan
func (l *Logger) Scan(r io.Reader) (cancel func()) { l.once.Do(func() { // add a marshaler once // in order to handle []byte and string // as its input. // Because scan doesn't care about // logging levels (because of the io.Reader) // Note: We don't use the `pio.Text` built'n marshaler // because we want to manage time log too. l.Printer.MarshalFunc(func(v interface{}) ([]byte, error) { var line []byte if b, ok := v.([]byte); ok { line = b } else if s, ok := v.(string); ok { line = []byte(s) } if len(line) == 0 { return nil, pio.ErrMarshalNotResponsible } formattedTime := time.Now().Format(l.TimeFormat) if formattedTime != "" { line = append([]byte(formattedTime+" "), line...) } return line, nil }) }) return l.Printer.Scan(r, true) }
go
func (l *Logger) Scan(r io.Reader) (cancel func()) { l.once.Do(func() { // add a marshaler once // in order to handle []byte and string // as its input. // Because scan doesn't care about // logging levels (because of the io.Reader) // Note: We don't use the `pio.Text` built'n marshaler // because we want to manage time log too. l.Printer.MarshalFunc(func(v interface{}) ([]byte, error) { var line []byte if b, ok := v.([]byte); ok { line = b } else if s, ok := v.(string); ok { line = []byte(s) } if len(line) == 0 { return nil, pio.ErrMarshalNotResponsible } formattedTime := time.Now().Format(l.TimeFormat) if formattedTime != "" { line = append([]byte(formattedTime+" "), line...) } return line, nil }) }) return l.Printer.Scan(r, true) }
[ "func", "(", "l", "*", "Logger", ")", "Scan", "(", "r", "io", ".", "Reader", ")", "(", "cancel", "func", "(", ")", ")", "{", "l", ".", "once", ".", "Do", "(", "func", "(", ")", "{", "// add a marshaler once", "// in order to handle []byte and string", ...
// Scan scans everything from "r" and prints // its new contents to the logger's Printer's Output, // forever or until the returning "cancel" is fired, once.
[ "Scan", "scans", "everything", "from", "r", "and", "prints", "its", "new", "contents", "to", "the", "logger", "s", "Printer", "s", "Output", "forever", "or", "until", "the", "returning", "cancel", "is", "fired", "once", "." ]
03be101463868edc5a81f094fc68a5f6c1b5503a
https://github.com/kataras/golog/blob/03be101463868edc5a81f094fc68a5f6c1b5503a/logger.go#L381-L412
14,908
kataras/golog
logger.go
Clone
func (l *Logger) Clone() *Logger { return &Logger{ Prefix: l.Prefix, Level: l.Level, TimeFormat: l.TimeFormat, Printer: l.Printer, handlers: l.handlers, children: newLoggerMap(), mu: sync.Mutex{}, once: sync.Once{}, } }
go
func (l *Logger) Clone() *Logger { return &Logger{ Prefix: l.Prefix, Level: l.Level, TimeFormat: l.TimeFormat, Printer: l.Printer, handlers: l.handlers, children: newLoggerMap(), mu: sync.Mutex{}, once: sync.Once{}, } }
[ "func", "(", "l", "*", "Logger", ")", "Clone", "(", ")", "*", "Logger", "{", "return", "&", "Logger", "{", "Prefix", ":", "l", ".", "Prefix", ",", "Level", ":", "l", ".", "Level", ",", "TimeFormat", ":", "l", ".", "TimeFormat", ",", "Printer", ":...
// Clone returns a copy of this "l" Logger. // This copy is returned as pointer as well.
[ "Clone", "returns", "a", "copy", "of", "this", "l", "Logger", ".", "This", "copy", "is", "returned", "as", "pointer", "as", "well", "." ]
03be101463868edc5a81f094fc68a5f6c1b5503a
https://github.com/kataras/golog/blob/03be101463868edc5a81f094fc68a5f6c1b5503a/logger.go#L416-L427
14,909
kataras/golog
log.go
FormatTime
func (l Log) FormatTime() string { if l.Logger.TimeFormat == "" { return "" } return l.Time.Format(l.Logger.TimeFormat) }
go
func (l Log) FormatTime() string { if l.Logger.TimeFormat == "" { return "" } return l.Time.Format(l.Logger.TimeFormat) }
[ "func", "(", "l", "Log", ")", "FormatTime", "(", ")", "string", "{", "if", "l", ".", "Logger", ".", "TimeFormat", "==", "\"", "\"", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "l", ".", "Time", ".", "Format", "(", "l", ".", "Logger", ...
// FormatTime returns the formatted `Time`.
[ "FormatTime", "returns", "the", "formatted", "Time", "." ]
03be101463868edc5a81f094fc68a5f6c1b5503a
https://github.com/kataras/golog/blob/03be101463868edc5a81f094fc68a5f6c1b5503a/log.go#L28-L33
14,910
tyler-smith/go-bip39
bip39.go
SetWordList
func SetWordList(list []string) { wordList = list wordMap = map[string]int{} for i, v := range wordList { wordMap[v] = i } }
go
func SetWordList(list []string) { wordList = list wordMap = map[string]int{} for i, v := range wordList { wordMap[v] = i } }
[ "func", "SetWordList", "(", "list", "[", "]", "string", ")", "{", "wordList", "=", "list", "\n", "wordMap", "=", "map", "[", "string", "]", "int", "{", "}", "\n", "for", "i", ",", "v", ":=", "range", "wordList", "{", "wordMap", "[", "v", "]", "="...
// SetWordList sets the list of words to use for mnemonics. Currently the list // that is set is used package-wide.
[ "SetWordList", "sets", "the", "list", "of", "words", "to", "use", "for", "mnemonics", ".", "Currently", "the", "list", "that", "is", "set", "is", "used", "package", "-", "wide", "." ]
dbb3b84ba2ef14e894f5e33d6c6e43641e665738
https://github.com/tyler-smith/go-bip39/blob/dbb3b84ba2ef14e894f5e33d6c6e43641e665738/bip39.go#L76-L82
14,911
tyler-smith/go-bip39
bip39.go
GetWordIndex
func GetWordIndex(word string) (int, bool) { idx, ok := wordMap[word] return idx, ok }
go
func GetWordIndex(word string) (int, bool) { idx, ok := wordMap[word] return idx, ok }
[ "func", "GetWordIndex", "(", "word", "string", ")", "(", "int", ",", "bool", ")", "{", "idx", ",", "ok", ":=", "wordMap", "[", "word", "]", "\n", "return", "idx", ",", "ok", "\n", "}" ]
// GetWordIndex gets word index in wordMap.
[ "GetWordIndex", "gets", "word", "index", "in", "wordMap", "." ]
dbb3b84ba2ef14e894f5e33d6c6e43641e665738
https://github.com/tyler-smith/go-bip39/blob/dbb3b84ba2ef14e894f5e33d6c6e43641e665738/bip39.go#L90-L93
14,912
tyler-smith/go-bip39
bip39.go
EntropyFromMnemonic
func EntropyFromMnemonic(mnemonic string) ([]byte, error) { mnemonicSlice, isValid := splitMnemonicWords(mnemonic) if !isValid { return nil, ErrInvalidMnemonic } // Decode the words into a big.Int. b := big.NewInt(0) for _, v := range mnemonicSlice { index, found := wordMap[v] if found == false { return nil, fmt.Errorf("word `%v` not found in reverse map", v) } var wordBytes [2]byte binary.BigEndian.PutUint16(wordBytes[:], uint16(index)) b = b.Mul(b, shift11BitsMask) b = b.Or(b, big.NewInt(0).SetBytes(wordBytes[:])) } // Build and add the checksum to the big.Int. checksum := big.NewInt(0) checksumMask := wordLengthChecksumMasksMapping[len(mnemonicSlice)] checksum = checksum.And(b, checksumMask) b.Div(b, big.NewInt(0).Add(checksumMask, bigOne)) // The entropy is the underlying bytes of the big.Int. Any upper bytes of // all 0's are not returned so we pad the beginning of the slice with empty // bytes if necessary. entropy := b.Bytes() entropy = padByteSlice(entropy, len(mnemonicSlice)/3*4) // Generate the checksum and compare with the one we got from the mneomnic. entropyChecksumBytes := computeChecksum(entropy) entropyChecksum := big.NewInt(int64(entropyChecksumBytes[0])) if l := len(mnemonicSlice); l != 24 { checksumShift := wordLengthChecksumShiftMapping[l] entropyChecksum.Div(entropyChecksum, checksumShift) } if checksum.Cmp(entropyChecksum) != 0 { return nil, ErrChecksumIncorrect } return entropy, nil }
go
func EntropyFromMnemonic(mnemonic string) ([]byte, error) { mnemonicSlice, isValid := splitMnemonicWords(mnemonic) if !isValid { return nil, ErrInvalidMnemonic } // Decode the words into a big.Int. b := big.NewInt(0) for _, v := range mnemonicSlice { index, found := wordMap[v] if found == false { return nil, fmt.Errorf("word `%v` not found in reverse map", v) } var wordBytes [2]byte binary.BigEndian.PutUint16(wordBytes[:], uint16(index)) b = b.Mul(b, shift11BitsMask) b = b.Or(b, big.NewInt(0).SetBytes(wordBytes[:])) } // Build and add the checksum to the big.Int. checksum := big.NewInt(0) checksumMask := wordLengthChecksumMasksMapping[len(mnemonicSlice)] checksum = checksum.And(b, checksumMask) b.Div(b, big.NewInt(0).Add(checksumMask, bigOne)) // The entropy is the underlying bytes of the big.Int. Any upper bytes of // all 0's are not returned so we pad the beginning of the slice with empty // bytes if necessary. entropy := b.Bytes() entropy = padByteSlice(entropy, len(mnemonicSlice)/3*4) // Generate the checksum and compare with the one we got from the mneomnic. entropyChecksumBytes := computeChecksum(entropy) entropyChecksum := big.NewInt(int64(entropyChecksumBytes[0])) if l := len(mnemonicSlice); l != 24 { checksumShift := wordLengthChecksumShiftMapping[l] entropyChecksum.Div(entropyChecksum, checksumShift) } if checksum.Cmp(entropyChecksum) != 0 { return nil, ErrChecksumIncorrect } return entropy, nil }
[ "func", "EntropyFromMnemonic", "(", "mnemonic", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "mnemonicSlice", ",", "isValid", ":=", "splitMnemonicWords", "(", "mnemonic", ")", "\n", "if", "!", "isValid", "{", "return", "nil", ",", "ErrInva...
// EntropyFromMnemonic takes a mnemonic generated by this library, // and returns the input entropy used to generate the given mnemonic. // An error is returned if the given mnemonic is invalid.
[ "EntropyFromMnemonic", "takes", "a", "mnemonic", "generated", "by", "this", "library", "and", "returns", "the", "input", "entropy", "used", "to", "generate", "the", "given", "mnemonic", ".", "An", "error", "is", "returned", "if", "the", "given", "mnemonic", "i...
dbb3b84ba2ef14e894f5e33d6c6e43641e665738
https://github.com/tyler-smith/go-bip39/blob/dbb3b84ba2ef14e894f5e33d6c6e43641e665738/bip39.go#L113-L158
14,913
tyler-smith/go-bip39
bip39.go
NewMnemonic
func NewMnemonic(entropy []byte) (string, error) { // Compute some lengths for convenience. entropyBitLength := len(entropy) * 8 checksumBitLength := entropyBitLength / 32 sentenceLength := (entropyBitLength + checksumBitLength) / 11 // Validate that the requested size is supported. err := validateEntropyBitSize(entropyBitLength) if err != nil { return "", err } // Add checksum to entropy. entropy = addChecksum(entropy) // Break entropy up into sentenceLength chunks of 11 bits. // For each word AND mask the rightmost 11 bits and find the word at that index. // Then bitshift entropy 11 bits right and repeat. // Add to the last empty slot so we can work with LSBs instead of MSB. // Entropy as an int so we can bitmask without worrying about bytes slices. entropyInt := new(big.Int).SetBytes(entropy) // Slice to hold words in. words := make([]string, sentenceLength) // Throw away big.Int for AND masking. word := big.NewInt(0) for i := sentenceLength - 1; i >= 0; i-- { // Get 11 right most bits and bitshift 11 to the right for next time. word.And(entropyInt, last11BitsMask) entropyInt.Div(entropyInt, shift11BitsMask) // Get the bytes representing the 11 bits as a 2 byte slice. wordBytes := padByteSlice(word.Bytes(), 2) // Convert bytes to an index and add that word to the list. words[i] = wordList[binary.BigEndian.Uint16(wordBytes)] } return strings.Join(words, " "), nil }
go
func NewMnemonic(entropy []byte) (string, error) { // Compute some lengths for convenience. entropyBitLength := len(entropy) * 8 checksumBitLength := entropyBitLength / 32 sentenceLength := (entropyBitLength + checksumBitLength) / 11 // Validate that the requested size is supported. err := validateEntropyBitSize(entropyBitLength) if err != nil { return "", err } // Add checksum to entropy. entropy = addChecksum(entropy) // Break entropy up into sentenceLength chunks of 11 bits. // For each word AND mask the rightmost 11 bits and find the word at that index. // Then bitshift entropy 11 bits right and repeat. // Add to the last empty slot so we can work with LSBs instead of MSB. // Entropy as an int so we can bitmask without worrying about bytes slices. entropyInt := new(big.Int).SetBytes(entropy) // Slice to hold words in. words := make([]string, sentenceLength) // Throw away big.Int for AND masking. word := big.NewInt(0) for i := sentenceLength - 1; i >= 0; i-- { // Get 11 right most bits and bitshift 11 to the right for next time. word.And(entropyInt, last11BitsMask) entropyInt.Div(entropyInt, shift11BitsMask) // Get the bytes representing the 11 bits as a 2 byte slice. wordBytes := padByteSlice(word.Bytes(), 2) // Convert bytes to an index and add that word to the list. words[i] = wordList[binary.BigEndian.Uint16(wordBytes)] } return strings.Join(words, " "), nil }
[ "func", "NewMnemonic", "(", "entropy", "[", "]", "byte", ")", "(", "string", ",", "error", ")", "{", "// Compute some lengths for convenience.", "entropyBitLength", ":=", "len", "(", "entropy", ")", "*", "8", "\n", "checksumBitLength", ":=", "entropyBitLength", ...
// NewMnemonic will return a string consisting of the mnemonic words for // the given entropy. // If the provide entropy is invalid, an error will be returned.
[ "NewMnemonic", "will", "return", "a", "string", "consisting", "of", "the", "mnemonic", "words", "for", "the", "given", "entropy", ".", "If", "the", "provide", "entropy", "is", "invalid", "an", "error", "will", "be", "returned", "." ]
dbb3b84ba2ef14e894f5e33d6c6e43641e665738
https://github.com/tyler-smith/go-bip39/blob/dbb3b84ba2ef14e894f5e33d6c6e43641e665738/bip39.go#L163-L205
14,914
tyler-smith/go-bip39
bip39.go
MnemonicToByteArray
func MnemonicToByteArray(mnemonic string, raw ...bool) ([]byte, error) { var ( mnemonicSlice = strings.Split(mnemonic, " ") entropyBitSize = len(mnemonicSlice) * 11 checksumBitSize = entropyBitSize % 32 fullByteSize = (entropyBitSize-checksumBitSize)/8 + 1 checksumByteSize = fullByteSize - (fullByteSize % 4) ) // Pre validate that the mnemonic is well formed and only contains words that // are present in the word list. if !IsMnemonicValid(mnemonic) { return nil, ErrInvalidMnemonic } // Convert word indices to a big.Int representing the entropy. checksummedEntropy := big.NewInt(0) modulo := big.NewInt(2048) for _, v := range mnemonicSlice { index := big.NewInt(int64(wordMap[v])) checksummedEntropy.Mul(checksummedEntropy, modulo) checksummedEntropy.Add(checksummedEntropy, index) } // Calculate the unchecksummed entropy so we can validate that the checksum is // correct. checksumModulo := big.NewInt(0).Exp(bigTwo, big.NewInt(int64(checksumBitSize)), nil) rawEntropy := big.NewInt(0).Div(checksummedEntropy, checksumModulo) // Convert big.Ints to byte padded byte slices. rawEntropyBytes := padByteSlice(rawEntropy.Bytes(), checksumByteSize) checksummedEntropyBytes := padByteSlice(checksummedEntropy.Bytes(), fullByteSize) // Validate that the checksum is correct. newChecksummedEntropyBytes := padByteSlice(addChecksum(rawEntropyBytes), fullByteSize) if !compareByteSlices(checksummedEntropyBytes, newChecksummedEntropyBytes) { return nil, ErrChecksumIncorrect } if len(raw) > 0 && raw[0] { return rawEntropyBytes, nil } return checksummedEntropyBytes, nil }
go
func MnemonicToByteArray(mnemonic string, raw ...bool) ([]byte, error) { var ( mnemonicSlice = strings.Split(mnemonic, " ") entropyBitSize = len(mnemonicSlice) * 11 checksumBitSize = entropyBitSize % 32 fullByteSize = (entropyBitSize-checksumBitSize)/8 + 1 checksumByteSize = fullByteSize - (fullByteSize % 4) ) // Pre validate that the mnemonic is well formed and only contains words that // are present in the word list. if !IsMnemonicValid(mnemonic) { return nil, ErrInvalidMnemonic } // Convert word indices to a big.Int representing the entropy. checksummedEntropy := big.NewInt(0) modulo := big.NewInt(2048) for _, v := range mnemonicSlice { index := big.NewInt(int64(wordMap[v])) checksummedEntropy.Mul(checksummedEntropy, modulo) checksummedEntropy.Add(checksummedEntropy, index) } // Calculate the unchecksummed entropy so we can validate that the checksum is // correct. checksumModulo := big.NewInt(0).Exp(bigTwo, big.NewInt(int64(checksumBitSize)), nil) rawEntropy := big.NewInt(0).Div(checksummedEntropy, checksumModulo) // Convert big.Ints to byte padded byte slices. rawEntropyBytes := padByteSlice(rawEntropy.Bytes(), checksumByteSize) checksummedEntropyBytes := padByteSlice(checksummedEntropy.Bytes(), fullByteSize) // Validate that the checksum is correct. newChecksummedEntropyBytes := padByteSlice(addChecksum(rawEntropyBytes), fullByteSize) if !compareByteSlices(checksummedEntropyBytes, newChecksummedEntropyBytes) { return nil, ErrChecksumIncorrect } if len(raw) > 0 && raw[0] { return rawEntropyBytes, nil } return checksummedEntropyBytes, nil }
[ "func", "MnemonicToByteArray", "(", "mnemonic", "string", ",", "raw", "...", "bool", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "(", "mnemonicSlice", "=", "strings", ".", "Split", "(", "mnemonic", ",", "\"", "\"", ")", "\n", "entropyBit...
// MnemonicToByteArray takes a mnemonic string and turns it into a byte array // suitable for creating another mnemonic. // An error is returned if the mnemonic is invalid.
[ "MnemonicToByteArray", "takes", "a", "mnemonic", "string", "and", "turns", "it", "into", "a", "byte", "array", "suitable", "for", "creating", "another", "mnemonic", ".", "An", "error", "is", "returned", "if", "the", "mnemonic", "is", "invalid", "." ]
dbb3b84ba2ef14e894f5e33d6c6e43641e665738
https://github.com/tyler-smith/go-bip39/blob/dbb3b84ba2ef14e894f5e33d6c6e43641e665738/bip39.go#L210-L254
14,915
tyler-smith/go-bip39
bip39.go
NewSeedWithErrorChecking
func NewSeedWithErrorChecking(mnemonic string, password string) ([]byte, error) { _, err := MnemonicToByteArray(mnemonic) if err != nil { return nil, err } return NewSeed(mnemonic, password), nil }
go
func NewSeedWithErrorChecking(mnemonic string, password string) ([]byte, error) { _, err := MnemonicToByteArray(mnemonic) if err != nil { return nil, err } return NewSeed(mnemonic, password), nil }
[ "func", "NewSeedWithErrorChecking", "(", "mnemonic", "string", ",", "password", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "_", ",", "err", ":=", "MnemonicToByteArray", "(", "mnemonic", ")", "\n", "if", "err", "!=", "nil", "{", "return...
// NewSeedWithErrorChecking creates a hashed seed output given the mnemonic string and a password. // An error is returned if the mnemonic is not convertible to a byte array.
[ "NewSeedWithErrorChecking", "creates", "a", "hashed", "seed", "output", "given", "the", "mnemonic", "string", "and", "a", "password", ".", "An", "error", "is", "returned", "if", "the", "mnemonic", "is", "not", "convertible", "to", "a", "byte", "array", "." ]
dbb3b84ba2ef14e894f5e33d6c6e43641e665738
https://github.com/tyler-smith/go-bip39/blob/dbb3b84ba2ef14e894f5e33d6c6e43641e665738/bip39.go#L258-L264
14,916
tyler-smith/go-bip39
bip39.go
NewSeed
func NewSeed(mnemonic string, password string) []byte { return pbkdf2.Key([]byte(mnemonic), []byte("mnemonic"+password), 2048, 64, sha512.New) }
go
func NewSeed(mnemonic string, password string) []byte { return pbkdf2.Key([]byte(mnemonic), []byte("mnemonic"+password), 2048, 64, sha512.New) }
[ "func", "NewSeed", "(", "mnemonic", "string", ",", "password", "string", ")", "[", "]", "byte", "{", "return", "pbkdf2", ".", "Key", "(", "[", "]", "byte", "(", "mnemonic", ")", ",", "[", "]", "byte", "(", "\"", "\"", "+", "password", ")", ",", "...
// NewSeed creates a hashed seed output given a provided string and password. // No checking is performed to validate that the string provided is a valid mnemonic.
[ "NewSeed", "creates", "a", "hashed", "seed", "output", "given", "a", "provided", "string", "and", "password", ".", "No", "checking", "is", "performed", "to", "validate", "that", "the", "string", "provided", "is", "a", "valid", "mnemonic", "." ]
dbb3b84ba2ef14e894f5e33d6c6e43641e665738
https://github.com/tyler-smith/go-bip39/blob/dbb3b84ba2ef14e894f5e33d6c6e43641e665738/bip39.go#L268-L270
14,917
tyler-smith/go-bip39
bip39.go
IsMnemonicValid
func IsMnemonicValid(mnemonic string) bool { // Create a list of all the words in the mnemonic sentence words := strings.Fields(mnemonic) // Get word count wordCount := len(words) // The number of words should be 12, 15, 18, 21 or 24 if wordCount%3 != 0 || wordCount < 12 || wordCount > 24 { return false } // Check if all words belong in the wordlist for _, word := range words { if _, ok := wordMap[word]; !ok { return false } } return true }
go
func IsMnemonicValid(mnemonic string) bool { // Create a list of all the words in the mnemonic sentence words := strings.Fields(mnemonic) // Get word count wordCount := len(words) // The number of words should be 12, 15, 18, 21 or 24 if wordCount%3 != 0 || wordCount < 12 || wordCount > 24 { return false } // Check if all words belong in the wordlist for _, word := range words { if _, ok := wordMap[word]; !ok { return false } } return true }
[ "func", "IsMnemonicValid", "(", "mnemonic", "string", ")", "bool", "{", "// Create a list of all the words in the mnemonic sentence", "words", ":=", "strings", ".", "Fields", "(", "mnemonic", ")", "\n\n", "// Get word count", "wordCount", ":=", "len", "(", "words", ")...
// IsMnemonicValid attempts to verify that the provided mnemonic is valid. // Validity is determined by both the number of words being appropriate, // and that all the words in the mnemonic are present in the word list.
[ "IsMnemonicValid", "attempts", "to", "verify", "that", "the", "provided", "mnemonic", "is", "valid", ".", "Validity", "is", "determined", "by", "both", "the", "number", "of", "words", "being", "appropriate", "and", "that", "all", "the", "words", "in", "the", ...
dbb3b84ba2ef14e894f5e33d6c6e43641e665738
https://github.com/tyler-smith/go-bip39/blob/dbb3b84ba2ef14e894f5e33d6c6e43641e665738/bip39.go#L275-L295
14,918
tyler-smith/go-bip39
bip39.go
padByteSlice
func padByteSlice(slice []byte, length int) []byte { offset := length - len(slice) if offset <= 0 { return slice } newSlice := make([]byte, length) copy(newSlice[offset:], slice) return newSlice }
go
func padByteSlice(slice []byte, length int) []byte { offset := length - len(slice) if offset <= 0 { return slice } newSlice := make([]byte, length) copy(newSlice[offset:], slice) return newSlice }
[ "func", "padByteSlice", "(", "slice", "[", "]", "byte", ",", "length", "int", ")", "[", "]", "byte", "{", "offset", ":=", "length", "-", "len", "(", "slice", ")", "\n", "if", "offset", "<=", "0", "{", "return", "slice", "\n", "}", "\n", "newSlice",...
// padByteSlice returns a byte slice of the given size with contents of the // given slice left padded and any empty spaces filled with 0's.
[ "padByteSlice", "returns", "a", "byte", "slice", "of", "the", "given", "size", "with", "contents", "of", "the", "given", "slice", "left", "padded", "and", "any", "empty", "spaces", "filled", "with", "0", "s", "." ]
dbb3b84ba2ef14e894f5e33d6c6e43641e665738
https://github.com/tyler-smith/go-bip39/blob/dbb3b84ba2ef14e894f5e33d6c6e43641e665738/bip39.go#L341-L349
14,919
nanopack/mist
clients/clients.go
New
func New(host, authtoken string) (*TCP, error) { client := &TCP{ host: host, messages: make(chan mist.Message), token: authtoken, } return client, client.connect() }
go
func New(host, authtoken string) (*TCP, error) { client := &TCP{ host: host, messages: make(chan mist.Message), token: authtoken, } return client, client.connect() }
[ "func", "New", "(", "host", ",", "authtoken", "string", ")", "(", "*", "TCP", ",", "error", ")", "{", "client", ":=", "&", "TCP", "{", "host", ":", "host", ",", "messages", ":", "make", "(", "chan", "mist", ".", "Message", ")", ",", "token", ":",...
// New attempts to connect to a running mist server at the clients specified // host and port.
[ "New", "attempts", "to", "connect", "to", "a", "running", "mist", "server", "at", "the", "clients", "specified", "host", "and", "port", "." ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/clients/clients.go#L28-L36
14,920
nanopack/mist
clients/clients.go
connect
func (c *TCP) connect() error { // attempt to connect to the server conn, err := net.Dial("tcp", c.host) if err != nil { return fmt.Errorf("Failed to dial '%s' - %s", c.host, err.Error()) } // set the connection for the client c.conn = conn // create a new json encoder for the clients connection c.encoder = json.NewEncoder(c.conn) // if the client was created with a token, authentication is needed if c.token != "" { err = c.encoder.Encode(&mist.Message{Command: "auth", Data: c.token}) if err != nil { return fmt.Errorf("Failed to send auth - %s", err.Error()) } } // ensure we are authorized/still connected (unauthorized clients get disconnected) c.Ping() decoder := json.NewDecoder(conn) msg := mist.Message{} if err := decoder.Decode(&msg); err != nil { conn.Close() close(c.messages) return fmt.Errorf("Ping failed, possibly bad token, or can't read from mist - %s", err.Error()) } // connection loop (blocking); continually read off the connection. Once something // is read, check to see if it's a message the client understands to be one of // its commands. If so attempt to execute the command. go func() { for { msg := mist.Message{} // decode an array value (Message) if err := decoder.Decode(&msg); err != nil { switch err { case io.EOF: lumber.Debug("[mist client] Mist terminated connection") case io.ErrUnexpectedEOF: lumber.Debug("[mist client] Mist terminated connection unexpectedly") default: lumber.Error("[mist client] Failed to get message from mist - %s", err.Error()) } conn.Close() close(c.messages) return } c.messages <- msg // read from this using the .Messages() function lumber.Trace("[mist client] Received message - %#v", msg) } }() return nil }
go
func (c *TCP) connect() error { // attempt to connect to the server conn, err := net.Dial("tcp", c.host) if err != nil { return fmt.Errorf("Failed to dial '%s' - %s", c.host, err.Error()) } // set the connection for the client c.conn = conn // create a new json encoder for the clients connection c.encoder = json.NewEncoder(c.conn) // if the client was created with a token, authentication is needed if c.token != "" { err = c.encoder.Encode(&mist.Message{Command: "auth", Data: c.token}) if err != nil { return fmt.Errorf("Failed to send auth - %s", err.Error()) } } // ensure we are authorized/still connected (unauthorized clients get disconnected) c.Ping() decoder := json.NewDecoder(conn) msg := mist.Message{} if err := decoder.Decode(&msg); err != nil { conn.Close() close(c.messages) return fmt.Errorf("Ping failed, possibly bad token, or can't read from mist - %s", err.Error()) } // connection loop (blocking); continually read off the connection. Once something // is read, check to see if it's a message the client understands to be one of // its commands. If so attempt to execute the command. go func() { for { msg := mist.Message{} // decode an array value (Message) if err := decoder.Decode(&msg); err != nil { switch err { case io.EOF: lumber.Debug("[mist client] Mist terminated connection") case io.ErrUnexpectedEOF: lumber.Debug("[mist client] Mist terminated connection unexpectedly") default: lumber.Error("[mist client] Failed to get message from mist - %s", err.Error()) } conn.Close() close(c.messages) return } c.messages <- msg // read from this using the .Messages() function lumber.Trace("[mist client] Received message - %#v", msg) } }() return nil }
[ "func", "(", "c", "*", "TCP", ")", "connect", "(", ")", "error", "{", "// attempt to connect to the server", "conn", ",", "err", ":=", "net", ".", "Dial", "(", "\"", "\"", ",", "c", ".", "host", ")", "\n", "if", "err", "!=", "nil", "{", "return", "...
// connect dials the remote mist server and handles any incoming responses back // from mist
[ "connect", "dials", "the", "remote", "mist", "server", "and", "handles", "any", "incoming", "responses", "back", "from", "mist" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/clients/clients.go#L40-L100
14,921
nanopack/mist
clients/clients.go
Ping
func (c *TCP) Ping() error { return c.encoder.Encode(&mist.Message{Command: "ping"}) }
go
func (c *TCP) Ping() error { return c.encoder.Encode(&mist.Message{Command: "ping"}) }
[ "func", "(", "c", "*", "TCP", ")", "Ping", "(", ")", "error", "{", "return", "c", ".", "encoder", ".", "Encode", "(", "&", "mist", ".", "Message", "{", "Command", ":", "\"", "\"", "}", ")", "\n", "}" ]
// Ping the server
[ "Ping", "the", "server" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/clients/clients.go#L103-L105
14,922
nanopack/mist
clients/clients.go
Subscribe
func (c *TCP) Subscribe(tags []string) error { if len(tags) == 0 { return fmt.Errorf("Unable to subscribe - missing tags") } return c.encoder.Encode(&mist.Message{Command: "subscribe", Tags: tags}) }
go
func (c *TCP) Subscribe(tags []string) error { if len(tags) == 0 { return fmt.Errorf("Unable to subscribe - missing tags") } return c.encoder.Encode(&mist.Message{Command: "subscribe", Tags: tags}) }
[ "func", "(", "c", "*", "TCP", ")", "Subscribe", "(", "tags", "[", "]", "string", ")", "error", "{", "if", "len", "(", "tags", ")", "==", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "c", ".", "e...
// Subscribe takes the specified tags and tells the server to subscribe to updates // on those tags, returning the tags and an error or nil
[ "Subscribe", "takes", "the", "specified", "tags", "and", "tells", "the", "server", "to", "subscribe", "to", "updates", "on", "those", "tags", "returning", "the", "tags", "and", "an", "error", "or", "nil" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/clients/clients.go#L109-L116
14,923
nanopack/mist
clients/clients.go
Publish
func (c *TCP) Publish(tags []string, data string) error { if len(tags) == 0 { return fmt.Errorf("Unable to publish - missing tags") } if data == "" { return fmt.Errorf("Unable to publish - missing data") } return c.encoder.Encode(&mist.Message{Command: "publish", Tags: tags, Data: data}) }
go
func (c *TCP) Publish(tags []string, data string) error { if len(tags) == 0 { return fmt.Errorf("Unable to publish - missing tags") } if data == "" { return fmt.Errorf("Unable to publish - missing data") } return c.encoder.Encode(&mist.Message{Command: "publish", Tags: tags, Data: data}) }
[ "func", "(", "c", "*", "TCP", ")", "Publish", "(", "tags", "[", "]", "string", ",", "data", "string", ")", "error", "{", "if", "len", "(", "tags", ")", "==", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "...
// Publish sends a message to the mist server to be published to all subscribed // clients
[ "Publish", "sends", "a", "message", "to", "the", "mist", "server", "to", "be", "published", "to", "all", "subscribed", "clients" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/clients/clients.go#L131-L142
14,924
nanopack/mist
clients/clients.go
PublishAfter
func (c *TCP) PublishAfter(tags []string, data string, delay time.Duration) error { go func() { <-time.After(delay) c.Publish(tags, data) }() return nil }
go
func (c *TCP) PublishAfter(tags []string, data string, delay time.Duration) error { go func() { <-time.After(delay) c.Publish(tags, data) }() return nil }
[ "func", "(", "c", "*", "TCP", ")", "PublishAfter", "(", "tags", "[", "]", "string", ",", "data", "string", ",", "delay", "time", ".", "Duration", ")", "error", "{", "go", "func", "(", ")", "{", "<-", "time", ".", "After", "(", "delay", ")", "\n",...
// PublishAfter sends a message to the mist server to be published to all subscribed // clients after a specified delay
[ "PublishAfter", "sends", "a", "message", "to", "the", "mist", "server", "to", "be", "published", "to", "all", "subscribed", "clients", "after", "a", "specified", "delay" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/clients/clients.go#L146-L152
14,925
nanopack/mist
server/handlers.go
handleListAll
func handleListAll(proxy *mist.Proxy, msg mist.Message) error { subscriptions := mist.Subscribers() proxy.Pipe <- mist.Message{Command: "listall", Tags: msg.Tags, Data: subscriptions} return nil }
go
func handleListAll(proxy *mist.Proxy, msg mist.Message) error { subscriptions := mist.Subscribers() proxy.Pipe <- mist.Message{Command: "listall", Tags: msg.Tags, Data: subscriptions} return nil }
[ "func", "handleListAll", "(", "proxy", "*", "mist", ".", "Proxy", ",", "msg", "mist", ".", "Message", ")", "error", "{", "subscriptions", ":=", "mist", ".", "Subscribers", "(", ")", "\n", "proxy", ".", "Pipe", "<-", "mist", ".", "Message", "{", "Comman...
// handleListAll - listall related
[ "handleListAll", "-", "listall", "related" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/server/handlers.go#L76-L80
14,926
nanopack/mist
server/handlers.go
handleWho
func handleWho(proxy *mist.Proxy, msg mist.Message) error { who, max := mist.Who() subscribers := fmt.Sprintf("Lifetime connections: %d\nSubscribers connected: %d", max, who) proxy.Pipe <- mist.Message{Command: "who", Tags: msg.Tags, Data: subscribers} return nil }
go
func handleWho(proxy *mist.Proxy, msg mist.Message) error { who, max := mist.Who() subscribers := fmt.Sprintf("Lifetime connections: %d\nSubscribers connected: %d", max, who) proxy.Pipe <- mist.Message{Command: "who", Tags: msg.Tags, Data: subscribers} return nil }
[ "func", "handleWho", "(", "proxy", "*", "mist", ".", "Proxy", ",", "msg", "mist", ".", "Message", ")", "error", "{", "who", ",", "max", ":=", "mist", ".", "Who", "(", ")", "\n", "subscribers", ":=", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\"", ...
// handleWho - who related
[ "handleWho", "-", "who", "related" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/server/handlers.go#L83-L88
14,927
nanopack/mist
auth/memory.go
findMemoryToken
func (a memory) findMemoryToken(token string) (mapset.Set, error) { // look for existing token entry, ok := a[token] if !ok { return nil, ErrTokenNotFound } return entry, nil }
go
func (a memory) findMemoryToken(token string) (mapset.Set, error) { // look for existing token entry, ok := a[token] if !ok { return nil, ErrTokenNotFound } return entry, nil }
[ "func", "(", "a", "memory", ")", "findMemoryToken", "(", "token", "string", ")", "(", "mapset", ".", "Set", ",", "error", ")", "{", "// look for existing token", "entry", ",", "ok", ":=", "a", "[", "token", "]", "\n", "if", "!", "ok", "{", "return", ...
// findMemoryToken attempts to find the desired token within memory
[ "findMemoryToken", "attempts", "to", "find", "the", "desired", "token", "within", "memory" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/auth/memory.go#L95-L104
14,928
nanopack/mist
core/proxy.go
List
func (p *Proxy) List() (data [][]string) { lumber.Trace("Proxy listing subscriptions...") p.RLock() data = p.subscriptions.ToSlice() p.RUnlock() return }
go
func (p *Proxy) List() (data [][]string) { lumber.Trace("Proxy listing subscriptions...") p.RLock() data = p.subscriptions.ToSlice() p.RUnlock() return }
[ "func", "(", "p", "*", "Proxy", ")", "List", "(", ")", "(", "data", "[", "]", "[", "]", "string", ")", "{", "lumber", ".", "Trace", "(", "\"", "\"", ")", "\n", "p", ".", "RLock", "(", ")", "\n", "data", "=", "p", ".", "subscriptions", ".", ...
// List returns a list of all current subscriptions
[ "List", "returns", "a", "list", "of", "all", "current", "subscriptions" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/core/proxy.go#L134-L141
14,929
nanopack/mist
server/server.go
Register
func Register(name string, auth handleFunc) { serversTex.Lock() servers[name] = auth serversTex.Unlock() }
go
func Register(name string, auth handleFunc) { serversTex.Lock() servers[name] = auth serversTex.Unlock() }
[ "func", "Register", "(", "name", "string", ",", "auth", "handleFunc", ")", "{", "serversTex", ".", "Lock", "(", ")", "\n", "servers", "[", "name", "]", "=", "auth", "\n", "serversTex", ".", "Unlock", "(", ")", "\n", "}" ]
// Register registers a new mist server
[ "Register", "registers", "a", "new", "mist", "server" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/server/server.go#L29-L33
14,930
nanopack/mist
core/subscriptions.go
Add
func (node *Node) Add(keys []string) { if len(keys) == 0 { return } sort.Strings(keys) node.add(keys) }
go
func (node *Node) Add(keys []string) { if len(keys) == 0 { return } sort.Strings(keys) node.add(keys) }
[ "func", "(", "node", "*", "Node", ")", "Add", "(", "keys", "[", "]", "string", ")", "{", "if", "len", "(", "keys", ")", "==", "0", "{", "return", "\n", "}", "\n\n", "sort", ".", "Strings", "(", "keys", ")", "\n", "node", ".", "add", "(", "key...
// Add sorts the keys and then attempts to add them
[ "Add", "sorts", "the", "keys", "and", "then", "attempts", "to", "add", "them" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/core/subscriptions.go#L34-L41
14,931
nanopack/mist
core/subscriptions.go
Remove
func (node *Node) Remove(keys []string) { if len(keys) == 0 { return } sort.Strings(keys) node.remove(keys) }
go
func (node *Node) Remove(keys []string) { if len(keys) == 0 { return } sort.Strings(keys) node.remove(keys) }
[ "func", "(", "node", "*", "Node", ")", "Remove", "(", "keys", "[", "]", "string", ")", "{", "if", "len", "(", "keys", ")", "==", "0", "{", "return", "\n", "}", "\n\n", "sort", ".", "Strings", "(", "keys", ")", "\n", "node", ".", "remove", "(", ...
// Remove sorts the keys and then attempts to remove them
[ "Remove", "sorts", "the", "keys", "and", "then", "attempts", "to", "remove", "them" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/core/subscriptions.go#L68-L76
14,932
nanopack/mist
core/subscriptions.go
Match
func (node *Node) Match(keys []string) bool { sort.Strings(keys) return node.match(keys) }
go
func (node *Node) Match(keys []string) bool { sort.Strings(keys) return node.match(keys) }
[ "func", "(", "node", "*", "Node", ")", "Match", "(", "keys", "[", "]", "string", ")", "bool", "{", "sort", ".", "Strings", "(", "keys", ")", "\n", "return", "node", ".", "match", "(", "keys", ")", "\n", "}" ]
// Match sorts the keys and then attempts to find a match
[ "Match", "sorts", "the", "keys", "and", "then", "attempts", "to", "find", "a", "match" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/core/subscriptions.go#L107-L110
14,933
nanopack/mist
core/subscriptions.go
ToSlice
func (node *Node) ToSlice() (list [][]string) { // iterate through each leaf appending it as a slice to the list of keys for leaf := range node.leaves { list = append(list, []string{leaf}) } // iterate through each branch getting its list of branches and appending those // to the list for branch, node := range node.branches { // get the current nodes slice of branches and leaves nodeSlice := node.ToSlice() // for each branch in the nodes list apppend the key to that key for _, nodeKey := range nodeSlice { list = append(list, append(nodeKey, branch)) } } // sort each list for _, l := range list { sort.Strings(l) } return }
go
func (node *Node) ToSlice() (list [][]string) { // iterate through each leaf appending it as a slice to the list of keys for leaf := range node.leaves { list = append(list, []string{leaf}) } // iterate through each branch getting its list of branches and appending those // to the list for branch, node := range node.branches { // get the current nodes slice of branches and leaves nodeSlice := node.ToSlice() // for each branch in the nodes list apppend the key to that key for _, nodeKey := range nodeSlice { list = append(list, append(nodeKey, branch)) } } // sort each list for _, l := range list { sort.Strings(l) } return }
[ "func", "(", "node", "*", "Node", ")", "ToSlice", "(", ")", "(", "list", "[", "]", "[", "]", "string", ")", "{", "// iterate through each leaf appending it as a slice to the list of keys", "for", "leaf", ":=", "range", "node", ".", "leaves", "{", "list", "=", ...
// ToSlice recurses down an entire node returning a list of all branches and leaves // as a slice of slices
[ "ToSlice", "recurses", "down", "an", "entire", "node", "returning", "a", "list", "of", "all", "branches", "and", "leaves", "as", "a", "slice", "of", "slices" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/core/subscriptions.go#L139-L164
14,934
nanopack/mist
auth/auth.go
Register
func Register(name string, auth handleFunc) { authTex.Lock() authenticators[name] = auth authTex.Unlock() }
go
func Register(name string, auth handleFunc) { authTex.Lock() authenticators[name] = auth authTex.Unlock() }
[ "func", "Register", "(", "name", "string", ",", "auth", "handleFunc", ")", "{", "authTex", ".", "Lock", "(", ")", "\n", "authenticators", "[", "name", "]", "=", "auth", "\n", "authTex", ".", "Unlock", "(", ")", "\n", "}" ]
// Register registers a new mist authenticator
[ "Register", "registers", "a", "new", "mist", "authenticator" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/auth/auth.go#L41-L45
14,935
nanopack/mist
auth/postgresql.go
NewPostgres
func NewPostgres(url *url.URL) (Authenticator, error) { host, port, err := net.SplitHostPort(url.Host) db := url.Query().Get("db") user := url.User.Username() // pass, _ := url.User.Password() pg := postgres(fmt.Sprintf("user=%s database=%s sslmode=disable host=%s port=%s", user, db, host, port)) // create the tables needed to support mist authentication if _, err = pg.exec(` CREATE TABLE IF NOT EXISTS tokens ( token text NOT NULL, token_id SERIAL UNIQUE NOT NULL, PRIMARY KEY (token) )`); err != nil { return pg, err } if _, err = pg.exec(` CREATE TABLE IF NOT EXISTS tags ( token_id integer NOT NULL REFERENCES tokens (token_id) ON DELETE CASCADE, tag text NOT NULL, PRIMARY KEY (token_id, tag) )`); err != nil { return pg, err } return pg, nil }
go
func NewPostgres(url *url.URL) (Authenticator, error) { host, port, err := net.SplitHostPort(url.Host) db := url.Query().Get("db") user := url.User.Username() // pass, _ := url.User.Password() pg := postgres(fmt.Sprintf("user=%s database=%s sslmode=disable host=%s port=%s", user, db, host, port)) // create the tables needed to support mist authentication if _, err = pg.exec(` CREATE TABLE IF NOT EXISTS tokens ( token text NOT NULL, token_id SERIAL UNIQUE NOT NULL, PRIMARY KEY (token) )`); err != nil { return pg, err } if _, err = pg.exec(` CREATE TABLE IF NOT EXISTS tags ( token_id integer NOT NULL REFERENCES tokens (token_id) ON DELETE CASCADE, tag text NOT NULL, PRIMARY KEY (token_id, tag) )`); err != nil { return pg, err } return pg, nil }
[ "func", "NewPostgres", "(", "url", "*", "url", ".", "URL", ")", "(", "Authenticator", ",", "error", ")", "{", "host", ",", "port", ",", "err", ":=", "net", ".", "SplitHostPort", "(", "url", ".", "Host", ")", "\n", "db", ":=", "url", ".", "Query", ...
// NewPostgres creates a new "postgres" Authenticator
[ "NewPostgres", "creates", "a", "new", "postgres", "Authenticator" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/auth/postgresql.go#L24-L53
14,936
nanopack/mist
auth/postgresql.go
query
func (a postgres) query(query string, args ...interface{}) (*sql.Rows, error) { client, err := a.connect() if err != nil { return nil, err } defer client.Close() return client.Query(query, args...) }
go
func (a postgres) query(query string, args ...interface{}) (*sql.Rows, error) { client, err := a.connect() if err != nil { return nil, err } defer client.Close() return client.Query(query, args...) }
[ "func", "(", "a", "postgres", ")", "query", "(", "query", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "*", "sql", ".", "Rows", ",", "error", ")", "{", "client", ",", "err", ":=", "a", ".", "connect", "(", ")", "\n", "if", "er...
// this could really be optimized a lot. instead of opening a new conenction for // each query, it should reuse connections
[ "this", "could", "really", "be", "optimized", "a", "lot", ".", "instead", "of", "opening", "a", "new", "conenction", "for", "each", "query", "it", "should", "reuse", "connections" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/auth/postgresql.go#L121-L129
14,937
nanopack/mist
auth/postgresql.go
exec
func (a postgres) exec(query string, args ...interface{}) (sql.Result, error) { client, err := a.connect() if err != nil { return nil, err } defer client.Close() return client.Exec(query, args...) }
go
func (a postgres) exec(query string, args ...interface{}) (sql.Result, error) { client, err := a.connect() if err != nil { return nil, err } defer client.Close() return client.Exec(query, args...) }
[ "func", "(", "a", "postgres", ")", "exec", "(", "query", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "sql", ".", "Result", ",", "error", ")", "{", "client", ",", "err", ":=", "a", ".", "connect", "(", ")", "\n", "if", "err", ...
// This could also be optimized a lot
[ "This", "could", "also", "be", "optimized", "a", "lot" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/auth/postgresql.go#L132-L140
14,938
nanopack/mist
core/mist.go
Subscribers
func Subscribers() string { subs := make(map[string]bool) // no duplicates // get tags all clients subscribed to for i := range subscribers { s := subscribers[i].subscriptions.ToSlice() for j := range s { for k := range s[j] { subs[s[j][k]] = true } } } // slice it subSlice := []string{} for k, _ := range subs { subSlice = append(subSlice, k) } return strings.Join(subSlice, " ") }
go
func Subscribers() string { subs := make(map[string]bool) // no duplicates // get tags all clients subscribed to for i := range subscribers { s := subscribers[i].subscriptions.ToSlice() for j := range s { for k := range s[j] { subs[s[j][k]] = true } } } // slice it subSlice := []string{} for k, _ := range subs { subSlice = append(subSlice, k) } return strings.Join(subSlice, " ") }
[ "func", "Subscribers", "(", ")", "string", "{", "subs", ":=", "make", "(", "map", "[", "string", "]", "bool", ")", "// no duplicates", "\n\n", "// get tags all clients subscribed to", "for", "i", ":=", "range", "subscribers", "{", "s", ":=", "subscribers", "["...
// Subscribers is listall related
[ "Subscribers", "is", "listall", "related" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/core/mist.go#L34-L54
14,939
nanopack/mist
core/mist.go
Who
func Who() (int, int) { // subs := make(map[string]bool) // no duplicates subs := []string{} // get tags all clients subscribed to for i := range subscribers { subs = append(subs, fmt.Sprint(subscribers[i].id)) } return len(subs), int(uid) }
go
func Who() (int, int) { // subs := make(map[string]bool) // no duplicates subs := []string{} // get tags all clients subscribed to for i := range subscribers { subs = append(subs, fmt.Sprint(subscribers[i].id)) } return len(subs), int(uid) }
[ "func", "Who", "(", ")", "(", "int", ",", "int", ")", "{", "// subs := make(map[string]bool) // no duplicates", "subs", ":=", "[", "]", "string", "{", "}", "\n\n", "// get tags all clients subscribed to", "for", "i", ":=", "range", "subscribers", "{", "subs", "=...
// Who is who related
[ "Who", "is", "who", "related" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/core/mist.go#L57-L67
14,940
nanopack/mist
core/mist.go
PublishAfter
func PublishAfter(tags []string, data string, delay time.Duration) error { go func() { <-time.After(delay) if err := Publish(tags, data); err != nil { // log this error and continue? lumber.Error("Failed to PublishAfter - %s", err.Error()) } }() return nil }
go
func PublishAfter(tags []string, data string, delay time.Duration) error { go func() { <-time.After(delay) if err := Publish(tags, data); err != nil { // log this error and continue? lumber.Error("Failed to PublishAfter - %s", err.Error()) } }() return nil }
[ "func", "PublishAfter", "(", "tags", "[", "]", "string", ",", "data", "string", ",", "delay", "time", ".", "Duration", ")", "error", "{", "go", "func", "(", ")", "{", "<-", "time", ".", "After", "(", "delay", ")", "\n", "if", "err", ":=", "Publish"...
// PublishAfter publishes to ALL subscribers. Usefull in client applications // who reuse the publish connection for subscribing
[ "PublishAfter", "publishes", "to", "ALL", "subscribers", ".", "Usefull", "in", "client", "applications", "who", "reuse", "the", "publish", "connection", "for", "subscribing" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/core/mist.go#L81-L91
14,941
nanopack/mist
core/mist.go
publish
func publish(pid uint32, tags []string, data string) error { if len(tags) == 0 { return fmt.Errorf("Failed to publish. Missing tags") } // if there are no subscribers, the message goes nowhere // // this could be more optimized, but it might not be an issue unless thousands // of clients are using mist. go func() { mutex.RLock() for _, subscriber := range subscribers { select { case <-subscriber.done: lumber.Trace("Subscriber done") // do nothing? default: // dont send this message to the publisher who just sent it if subscriber.id == pid { lumber.Trace("Subscriber is publisher, skipping publish") continue } // create message msg := Message{Command: "publish", Tags: tags, Data: data} // we don't want this operation blocking the range of other subscribers // waiting to get messages go func(p *Proxy, msg Message) { p.check <- msg lumber.Trace("Published message") }(subscriber, msg) } } mutex.RUnlock() }() return nil }
go
func publish(pid uint32, tags []string, data string) error { if len(tags) == 0 { return fmt.Errorf("Failed to publish. Missing tags") } // if there are no subscribers, the message goes nowhere // // this could be more optimized, but it might not be an issue unless thousands // of clients are using mist. go func() { mutex.RLock() for _, subscriber := range subscribers { select { case <-subscriber.done: lumber.Trace("Subscriber done") // do nothing? default: // dont send this message to the publisher who just sent it if subscriber.id == pid { lumber.Trace("Subscriber is publisher, skipping publish") continue } // create message msg := Message{Command: "publish", Tags: tags, Data: data} // we don't want this operation blocking the range of other subscribers // waiting to get messages go func(p *Proxy, msg Message) { p.check <- msg lumber.Trace("Published message") }(subscriber, msg) } } mutex.RUnlock() }() return nil }
[ "func", "publish", "(", "pid", "uint32", ",", "tags", "[", "]", "string", ",", "data", "string", ")", "error", "{", "if", "len", "(", "tags", ")", "==", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// if the...
// publish publishes to all subscribers except the one who issued the publish
[ "publish", "publishes", "to", "all", "subscribers", "except", "the", "one", "who", "issued", "the", "publish" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/core/mist.go#L94-L135
14,942
nanopack/mist
core/mist.go
subscribe
func subscribe(p *Proxy) { lumber.Trace("Adding proxy to subscribers...") mutex.Lock() subscribers[p.id] = p mutex.Unlock() }
go
func subscribe(p *Proxy) { lumber.Trace("Adding proxy to subscribers...") mutex.Lock() subscribers[p.id] = p mutex.Unlock() }
[ "func", "subscribe", "(", "p", "*", "Proxy", ")", "{", "lumber", ".", "Trace", "(", "\"", "\"", ")", "\n\n", "mutex", ".", "Lock", "(", ")", "\n", "subscribers", "[", "p", ".", "id", "]", "=", "p", "\n", "mutex", ".", "Unlock", "(", ")", "\n", ...
// subscribe adds a proxy to the list of mist subscribers; we need this so that // we can lock this process incase multiple proxies are subscribing at the same // time
[ "subscribe", "adds", "a", "proxy", "to", "the", "list", "of", "mist", "subscribers", ";", "we", "need", "this", "so", "that", "we", "can", "lock", "this", "process", "incase", "multiple", "proxies", "are", "subscribing", "at", "the", "same", "time" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/core/mist.go#L140-L146
14,943
nanopack/mist
core/mist.go
unsubscribe
func unsubscribe(pid uint32) { lumber.Trace("Removing proxy from subscribers...") mutex.Lock() delete(subscribers, pid) mutex.Unlock() }
go
func unsubscribe(pid uint32) { lumber.Trace("Removing proxy from subscribers...") mutex.Lock() delete(subscribers, pid) mutex.Unlock() }
[ "func", "unsubscribe", "(", "pid", "uint32", ")", "{", "lumber", ".", "Trace", "(", "\"", "\"", ")", "\n\n", "mutex", ".", "Lock", "(", ")", "\n", "delete", "(", "subscribers", ",", "pid", ")", "\n", "mutex", ".", "Unlock", "(", ")", "\n", "}" ]
// unsubscribe removes a proxy from the list of mist subscribers; we need this // so that we can lock this process incase multiple proxies are unsubscribing at // the same time
[ "unsubscribe", "removes", "a", "proxy", "from", "the", "list", "of", "mist", "subscribers", ";", "we", "need", "this", "so", "that", "we", "can", "lock", "this", "process", "incase", "multiple", "proxies", "are", "unsubscribing", "at", "the", "same", "time" ...
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/core/mist.go#L151-L157
14,944
nanopack/mist
auth/scribble.go
NewScribble
func NewScribble(url *url.URL) (Authenticator, error) { // get the desired location of the scribble database dir := url.Query().Get("db") // if no database location is provided, fail if dir == "" { return nil, fmt.Errorf("Missing database location in scheme (?db=)") } // create a new scribble database at the specified location db, err := scribbleDB.New(dir, nil) if err != nil { return nil, err } return &scribble{driver: db}, nil }
go
func NewScribble(url *url.URL) (Authenticator, error) { // get the desired location of the scribble database dir := url.Query().Get("db") // if no database location is provided, fail if dir == "" { return nil, fmt.Errorf("Missing database location in scheme (?db=)") } // create a new scribble database at the specified location db, err := scribbleDB.New(dir, nil) if err != nil { return nil, err } return &scribble{driver: db}, nil }
[ "func", "NewScribble", "(", "url", "*", "url", ".", "URL", ")", "(", "Authenticator", ",", "error", ")", "{", "// get the desired location of the scribble database", "dir", ":=", "url", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", "\n\n", "// ...
// NewScribble creates a new "scribble" authenticator
[ "NewScribble", "creates", "a", "new", "scribble", "authenticator" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/auth/scribble.go#L30-L47
14,945
nanopack/mist
auth/scribble.go
findScribbleToken
func (a *scribble) findScribbleToken(token string) (entry scribbleToken, err error) { // look for existing token if err = a.driver.Read("tokens", token, &entry); err != nil { return entry, err } return entry, nil }
go
func (a *scribble) findScribbleToken(token string) (entry scribbleToken, err error) { // look for existing token if err = a.driver.Read("tokens", token, &entry); err != nil { return entry, err } return entry, nil }
[ "func", "(", "a", "*", "scribble", ")", "findScribbleToken", "(", "token", "string", ")", "(", "entry", "scribbleToken", ",", "err", "error", ")", "{", "// look for existing token", "if", "err", "=", "a", ".", "driver", ".", "Read", "(", "\"", "\"", ",",...
// findScribbleToken attempts to find the desired token within "scribble"
[ "findScribbleToken", "attempts", "to", "find", "the", "desired", "token", "within", "scribble" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/auth/scribble.go#L129-L137
14,946
nanopack/mist
server/http.go
StartHTTP
func StartHTTP(uri string, errChan chan<- error) { if err := newHTTP(uri); err != nil { errChan <- fmt.Errorf("Unable to start mist http listener - %s", err.Error()) } }
go
func StartHTTP(uri string, errChan chan<- error) { if err := newHTTP(uri); err != nil { errChan <- fmt.Errorf("Unable to start mist http listener - %s", err.Error()) } }
[ "func", "StartHTTP", "(", "uri", "string", ",", "errChan", "chan", "<-", "error", ")", "{", "if", "err", ":=", "newHTTP", "(", "uri", ")", ";", "err", "!=", "nil", "{", "errChan", "<-", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ".", "Err...
// StartHTTP starts a mist server listening over HTTP
[ "StartHTTP", "starts", "a", "mist", "server", "listening", "over", "HTTP" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/server/http.go#L23-L27
14,947
nanopack/mist
server/http.go
routes
func routes() *pat.Router { Router.Get("/ping", func(rw http.ResponseWriter, req *http.Request) { rw.Write([]byte("pong\n")) }) // Router.Get("/list", handleRequest(list)) // Router.Get("/subscribe", handleRequest(subscribe)) // Router.Get("/unsubscribe", handleRequest(unsubscribe)) return Router }
go
func routes() *pat.Router { Router.Get("/ping", func(rw http.ResponseWriter, req *http.Request) { rw.Write([]byte("pong\n")) }) // Router.Get("/list", handleRequest(list)) // Router.Get("/subscribe", handleRequest(subscribe)) // Router.Get("/unsubscribe", handleRequest(unsubscribe)) return Router }
[ "func", "routes", "(", ")", "*", "pat", ".", "Router", "{", "Router", ".", "Get", "(", "\"", "\"", ",", "func", "(", "rw", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "rw", ".", "Write", "(", "[", "]", "byt...
// routes registers all api routes with the router
[ "routes", "registers", "all", "api", "routes", "with", "the", "router" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/server/http.go#L42-L51
14,948
nanopack/mist
server/http.go
handleRequest
func handleRequest(fn func(http.ResponseWriter, *http.Request)) http.HandlerFunc { return func(rw http.ResponseWriter, req *http.Request) { fn(rw, req) } }
go
func handleRequest(fn func(http.ResponseWriter, *http.Request)) http.HandlerFunc { return func(rw http.ResponseWriter, req *http.Request) { fn(rw, req) } }
[ "func", "handleRequest", "(", "fn", "func", "(", "http", ".", "ResponseWriter", ",", "*", "http", ".", "Request", ")", ")", "http", ".", "HandlerFunc", "{", "return", "func", "(", "rw", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Requ...
// handleRequest is a wrapper for the actual route handler, simply to provide some // debug output
[ "handleRequest", "is", "a", "wrapper", "for", "the", "actual", "route", "handler", "simply", "to", "provide", "some", "debug", "output" ]
339c892519ed924d95ff289ecf0b7c7068879207
https://github.com/nanopack/mist/blob/339c892519ed924d95ff289ecf0b7c7068879207/server/http.go#L55-L59
14,949
apcera/gssapi
spnego/spnego_server.go
Negotiate
func (k KerberizedServer) Negotiate(cred *gssapi.CredId, inHeader, outHeader http.Header) (string, int, error) { var challengeHeader, authHeader string var challengeStatus int if k.UseProxyAuthentication { challengeHeader = "Proxy-Authenticate" challengeStatus = http.StatusProxyAuthRequired authHeader = "Proxy-Authorization" } else { challengeHeader = "WWW-Authenticate" challengeStatus = http.StatusUnauthorized authHeader = "Authorization" } negotiate, inputToken := CheckSPNEGONegotiate(k.Lib, inHeader, authHeader) defer inputToken.Release() // Here, challenge the client to initiate the security context. The first // request a client has made will often be unauthenticated, so we return a // 401, which the client handles. if !negotiate || inputToken.Length() == 0 { AddSPNEGONegotiate(outHeader, challengeHeader, inputToken) return "", challengeStatus, errors.New("SPNEGO: unauthorized") } // FIXME: GSS_S_CONTINUED_NEEDED handling? ctx, srcName, _, outputToken, _, _, delegatedCredHandle, err := k.AcceptSecContext(k.GSS_C_NO_CONTEXT, cred, inputToken, k.GSS_C_NO_CHANNEL_BINDINGS) if err != nil { return "", http.StatusBadRequest, err } delegatedCredHandle.Release() ctx.DeleteSecContext() outputToken.Release() defer srcName.Release() return srcName.String(), http.StatusOK, nil }
go
func (k KerberizedServer) Negotiate(cred *gssapi.CredId, inHeader, outHeader http.Header) (string, int, error) { var challengeHeader, authHeader string var challengeStatus int if k.UseProxyAuthentication { challengeHeader = "Proxy-Authenticate" challengeStatus = http.StatusProxyAuthRequired authHeader = "Proxy-Authorization" } else { challengeHeader = "WWW-Authenticate" challengeStatus = http.StatusUnauthorized authHeader = "Authorization" } negotiate, inputToken := CheckSPNEGONegotiate(k.Lib, inHeader, authHeader) defer inputToken.Release() // Here, challenge the client to initiate the security context. The first // request a client has made will often be unauthenticated, so we return a // 401, which the client handles. if !negotiate || inputToken.Length() == 0 { AddSPNEGONegotiate(outHeader, challengeHeader, inputToken) return "", challengeStatus, errors.New("SPNEGO: unauthorized") } // FIXME: GSS_S_CONTINUED_NEEDED handling? ctx, srcName, _, outputToken, _, _, delegatedCredHandle, err := k.AcceptSecContext(k.GSS_C_NO_CONTEXT, cred, inputToken, k.GSS_C_NO_CHANNEL_BINDINGS) if err != nil { return "", http.StatusBadRequest, err } delegatedCredHandle.Release() ctx.DeleteSecContext() outputToken.Release() defer srcName.Release() return srcName.String(), http.StatusOK, nil }
[ "func", "(", "k", "KerberizedServer", ")", "Negotiate", "(", "cred", "*", "gssapi", ".", "CredId", ",", "inHeader", ",", "outHeader", "http", ".", "Header", ")", "(", "string", ",", "int", ",", "error", ")", "{", "var", "challengeHeader", ",", "authHeade...
// Negotiate handles the SPNEGO client-server negotiation. Negotiate will likely // be invoked multiple times; a 200 or 400 response code are terminating // conditions, whereas a 401 or 407 means that the client should respond to the // challenge that we send.
[ "Negotiate", "handles", "the", "SPNEGO", "client", "-", "server", "negotiation", ".", "Negotiate", "will", "likely", "be", "invoked", "multiple", "times", ";", "a", "200", "or", "400", "response", "code", "are", "terminating", "conditions", "whereas", "a", "40...
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/spnego/spnego_server.go#L62-L99
14,950
apcera/gssapi
oid_set.go
MakeOIDSet
func (lib *Lib) MakeOIDSet(oids ...*OID) (s *OIDSet, err error) { s = &OIDSet{ Lib: lib, } var min C.OM_uint32 maj := C.wrap_gss_create_empty_oid_set(s.Fp_gss_create_empty_oid_set, &min, &s.C_gss_OID_set) err = s.stashLastStatus(maj, min) if err != nil { return nil, err } err = s.Add(oids...) if err != nil { return nil, err } return s, nil }
go
func (lib *Lib) MakeOIDSet(oids ...*OID) (s *OIDSet, err error) { s = &OIDSet{ Lib: lib, } var min C.OM_uint32 maj := C.wrap_gss_create_empty_oid_set(s.Fp_gss_create_empty_oid_set, &min, &s.C_gss_OID_set) err = s.stashLastStatus(maj, min) if err != nil { return nil, err } err = s.Add(oids...) if err != nil { return nil, err } return s, nil }
[ "func", "(", "lib", "*", "Lib", ")", "MakeOIDSet", "(", "oids", "...", "*", "OID", ")", "(", "s", "*", "OIDSet", ",", "err", "error", ")", "{", "s", "=", "&", "OIDSet", "{", "Lib", ":", "lib", ",", "}", "\n\n", "var", "min", "C", ".", "OM_uin...
// MakeOIDSet makes an OIDSet prepopulated with the given OIDs.
[ "MakeOIDSet", "makes", "an", "OIDSet", "prepopulated", "with", "the", "given", "OIDs", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/oid_set.go#L84-L103
14,951
apcera/gssapi
oid_set.go
Release
func (s *OIDSet) Release() (err error) { if s == nil || s.C_gss_OID_set == nil { return nil } var min C.OM_uint32 maj := C.wrap_gss_release_oid_set(s.Fp_gss_release_oid_set, &min, &s.C_gss_OID_set) return s.stashLastStatus(maj, min) }
go
func (s *OIDSet) Release() (err error) { if s == nil || s.C_gss_OID_set == nil { return nil } var min C.OM_uint32 maj := C.wrap_gss_release_oid_set(s.Fp_gss_release_oid_set, &min, &s.C_gss_OID_set) return s.stashLastStatus(maj, min) }
[ "func", "(", "s", "*", "OIDSet", ")", "Release", "(", ")", "(", "err", "error", ")", "{", "if", "s", "==", "nil", "||", "s", ".", "C_gss_OID_set", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "var", "min", "C", ".", "OM_uint32", "\n", ...
// Release frees all C memory associated with an OIDSet.
[ "Release", "frees", "all", "C", "memory", "associated", "with", "an", "OIDSet", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/oid_set.go#L106-L114
14,952
apcera/gssapi
oid_set.go
Add
func (s *OIDSet) Add(oids ...*OID) (err error) { var min C.OM_uint32 for _, oid := range oids { maj := C.wrap_gss_add_oid_set_member(s.Fp_gss_add_oid_set_member, &min, oid.C_gss_OID, &s.C_gss_OID_set) err = s.stashLastStatus(maj, min) if err != nil { return err } } return nil }
go
func (s *OIDSet) Add(oids ...*OID) (err error) { var min C.OM_uint32 for _, oid := range oids { maj := C.wrap_gss_add_oid_set_member(s.Fp_gss_add_oid_set_member, &min, oid.C_gss_OID, &s.C_gss_OID_set) err = s.stashLastStatus(maj, min) if err != nil { return err } } return nil }
[ "func", "(", "s", "*", "OIDSet", ")", "Add", "(", "oids", "...", "*", "OID", ")", "(", "err", "error", ")", "{", "var", "min", "C", ".", "OM_uint32", "\n", "for", "_", ",", "oid", ":=", "range", "oids", "{", "maj", ":=", "C", ".", "wrap_gss_add...
// Add adds OIDs to an OIDSet.
[ "Add", "adds", "OIDs", "to", "an", "OIDSet", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/oid_set.go#L117-L129
14,953
apcera/gssapi
oid_set.go
Length
func (s *OIDSet) Length() int { if s == nil { return 0 } return int(s.C_gss_OID_set.count) }
go
func (s *OIDSet) Length() int { if s == nil { return 0 } return int(s.C_gss_OID_set.count) }
[ "func", "(", "s", "*", "OIDSet", ")", "Length", "(", ")", "int", "{", "if", "s", "==", "nil", "{", "return", "0", "\n", "}", "\n", "return", "int", "(", "s", ".", "C_gss_OID_set", ".", "count", ")", "\n", "}" ]
// Length returns the number of OIDs in a set.
[ "Length", "returns", "the", "number", "of", "OIDs", "in", "a", "set", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/oid_set.go#L153-L158
14,954
apcera/gssapi
oid_set.go
Get
func (s *OIDSet) Get(index int) (*OID, error) { if s == nil || index < 0 || index >= int(s.C_gss_OID_set.count) { return nil, fmt.Errorf("index %d out of bounds", index) } oid := s.NewOID() oid.C_gss_OID = C.get_oid_set_member(s.C_gss_OID_set, C.int(index)) return oid, nil }
go
func (s *OIDSet) Get(index int) (*OID, error) { if s == nil || index < 0 || index >= int(s.C_gss_OID_set.count) { return nil, fmt.Errorf("index %d out of bounds", index) } oid := s.NewOID() oid.C_gss_OID = C.get_oid_set_member(s.C_gss_OID_set, C.int(index)) return oid, nil }
[ "func", "(", "s", "*", "OIDSet", ")", "Get", "(", "index", "int", ")", "(", "*", "OID", ",", "error", ")", "{", "if", "s", "==", "nil", "||", "index", "<", "0", "||", "index", ">=", "int", "(", "s", ".", "C_gss_OID_set", ".", "count", ")", "{...
// Get returns a specific OID from the set. The memory will be released when the // set itself is released.
[ "Get", "returns", "a", "specific", "OID", "from", "the", "set", ".", "The", "memory", "will", "be", "released", "when", "the", "set", "itself", "is", "released", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/oid_set.go#L162-L169
14,955
apcera/gssapi
lib.go
Path
func (o *Options) Path() string { switch { case o.LibPath != "": return o.LibPath case o.LoadDefault == MIT: return appendOSExt("libgssapi_krb5") case o.LoadDefault == Heimdal: return appendOSExt("libgssapi") } return "" }
go
func (o *Options) Path() string { switch { case o.LibPath != "": return o.LibPath case o.LoadDefault == MIT: return appendOSExt("libgssapi_krb5") case o.LoadDefault == Heimdal: return appendOSExt("libgssapi") } return "" }
[ "func", "(", "o", "*", "Options", ")", "Path", "(", ")", "string", "{", "switch", "{", "case", "o", ".", "LibPath", "!=", "\"", "\"", ":", "return", "o", ".", "LibPath", "\n\n", "case", "o", ".", "LoadDefault", "==", "MIT", ":", "return", "appendOS...
// Path returns the chosen gssapi library path that we're looking for.
[ "Path", "returns", "the", "chosen", "gssapi", "library", "path", "that", "we", "re", "looking", "for", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/lib.go#L221-L233
14,956
apcera/gssapi
lib.go
Load
func Load(o *Options) (*Lib, error) { if o == nil { o = &Options{} } // We get the error in a separate call, so we need to lock OS thread runtime.LockOSThread() defer runtime.UnlockOSThread() lib := &Lib{ Printers: o.Printers, } if o.Krb5Config != "" { err := os.Setenv("KRB5_CONFIG", o.Krb5Config) if err != nil { return nil, err } } if o.Krb5Ktname != "" { err := os.Setenv("KRB5_KTNAME", o.Krb5Ktname) if err != nil { return nil, err } } path := o.Path() lib.Debug(fmt.Sprintf("Loading %q", path)) lib_cs := C.CString(path) defer C.free(unsafe.Pointer(lib_cs)) // we don't use RTLD_FIRST, it might be the case that the GSSAPI lib // delegates symbols to other libs it links against (eg, Kerberos) lib.handle = C.dlopen(lib_cs, C.RTLD_NOW|C.RTLD_LOCAL) if lib.handle == nil { return nil, fmt.Errorf("%s", C.GoString(C.dlerror())) } err := lib.populateFunctions() if err != nil { lib.Unload() return nil, err } lib.initConstants() return lib, nil }
go
func Load(o *Options) (*Lib, error) { if o == nil { o = &Options{} } // We get the error in a separate call, so we need to lock OS thread runtime.LockOSThread() defer runtime.UnlockOSThread() lib := &Lib{ Printers: o.Printers, } if o.Krb5Config != "" { err := os.Setenv("KRB5_CONFIG", o.Krb5Config) if err != nil { return nil, err } } if o.Krb5Ktname != "" { err := os.Setenv("KRB5_KTNAME", o.Krb5Ktname) if err != nil { return nil, err } } path := o.Path() lib.Debug(fmt.Sprintf("Loading %q", path)) lib_cs := C.CString(path) defer C.free(unsafe.Pointer(lib_cs)) // we don't use RTLD_FIRST, it might be the case that the GSSAPI lib // delegates symbols to other libs it links against (eg, Kerberos) lib.handle = C.dlopen(lib_cs, C.RTLD_NOW|C.RTLD_LOCAL) if lib.handle == nil { return nil, fmt.Errorf("%s", C.GoString(C.dlerror())) } err := lib.populateFunctions() if err != nil { lib.Unload() return nil, err } lib.initConstants() return lib, nil }
[ "func", "Load", "(", "o", "*", "Options", ")", "(", "*", "Lib", ",", "error", ")", "{", "if", "o", "==", "nil", "{", "o", "=", "&", "Options", "{", "}", "\n", "}", "\n\n", "// We get the error in a separate call, so we need to lock OS thread", "runtime", "...
// Load attempts to load a dynamically-linked gssapi library from the path // specified by the supplied Options.
[ "Load", "attempts", "to", "load", "a", "dynamically", "-", "linked", "gssapi", "library", "from", "the", "path", "specified", "by", "the", "supplied", "Options", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/lib.go#L237-L285
14,957
apcera/gssapi
lib.go
Unload
func (lib *Lib) Unload() error { if lib == nil || lib.handle == nil { return nil } runtime.LockOSThread() defer runtime.UnlockOSThread() i := C.dlclose(lib.handle) if i == -1 { return fmt.Errorf("%s", C.GoString(C.dlerror())) } lib.handle = nil return nil }
go
func (lib *Lib) Unload() error { if lib == nil || lib.handle == nil { return nil } runtime.LockOSThread() defer runtime.UnlockOSThread() i := C.dlclose(lib.handle) if i == -1 { return fmt.Errorf("%s", C.GoString(C.dlerror())) } lib.handle = nil return nil }
[ "func", "(", "lib", "*", "Lib", ")", "Unload", "(", ")", "error", "{", "if", "lib", "==", "nil", "||", "lib", ".", "handle", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "runtime", ".", "LockOSThread", "(", ")", "\n", "defer", "runtime", ...
// Unload closes the handle to the dynamically-linked gssapi library.
[ "Unload", "closes", "the", "handle", "to", "the", "dynamically", "-", "linked", "gssapi", "library", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/lib.go#L288-L303
14,958
apcera/gssapi
lib.go
populateFunctions
func (lib *Lib) populateFunctions() error { libT := reflect.TypeOf(lib.ftable) functionsV := reflect.ValueOf(lib).Elem().FieldByName("ftable") n := libT.NumField() for i := 0; i < n; i++ { // Get the field name, and make sure it's an Fp_. f := libT.FieldByIndex([]int{i}) if !strings.HasPrefix(f.Name, fpPrefix) { return fmt.Errorf( "Unexpected: field %q does not start with %q", f.Name, fpPrefix) } // Resolve the symbol. cfname := C.CString(f.Name[len(fpPrefix):]) v := C.dlsym(lib.handle, cfname) C.free(unsafe.Pointer(cfname)) if v == nil { return fmt.Errorf("%s", C.GoString(C.dlerror())) } // Save the value into the struct functionsV.FieldByIndex([]int{i}).SetPointer(v) } return nil }
go
func (lib *Lib) populateFunctions() error { libT := reflect.TypeOf(lib.ftable) functionsV := reflect.ValueOf(lib).Elem().FieldByName("ftable") n := libT.NumField() for i := 0; i < n; i++ { // Get the field name, and make sure it's an Fp_. f := libT.FieldByIndex([]int{i}) if !strings.HasPrefix(f.Name, fpPrefix) { return fmt.Errorf( "Unexpected: field %q does not start with %q", f.Name, fpPrefix) } // Resolve the symbol. cfname := C.CString(f.Name[len(fpPrefix):]) v := C.dlsym(lib.handle, cfname) C.free(unsafe.Pointer(cfname)) if v == nil { return fmt.Errorf("%s", C.GoString(C.dlerror())) } // Save the value into the struct functionsV.FieldByIndex([]int{i}).SetPointer(v) } return nil }
[ "func", "(", "lib", "*", "Lib", ")", "populateFunctions", "(", ")", "error", "{", "libT", ":=", "reflect", ".", "TypeOf", "(", "lib", ".", "ftable", ")", "\n", "functionsV", ":=", "reflect", ".", "ValueOf", "(", "lib", ")", ".", "Elem", "(", ")", "...
// populateFunctions ranges over the library's ftable, initializing each // function inside. Assumes that the caller executes runtime.LockOSThread.
[ "populateFunctions", "ranges", "over", "the", "library", "s", "ftable", "initializing", "each", "function", "inside", ".", "Assumes", "that", "the", "caller", "executes", "runtime", ".", "LockOSThread", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/lib.go#L318-L346
14,959
apcera/gssapi
lib.go
initConstants
func (lib *Lib) initConstants() { lib.GSS_C_NO_BUFFER = &Buffer{ Lib: lib, // C_gss_buffer_t: C.GSS_C_NO_BUFFER, already nil // alloc: allocNone, already 0 } lib.GSS_C_NO_OID = lib.NewOID() lib.GSS_C_NO_OID_SET = lib.NewOIDSet() lib.GSS_C_NO_CONTEXT = lib.NewCtxId() lib.GSS_C_NO_CREDENTIAL = lib.NewCredId() lib.GSS_C_NT_USER_NAME = &OID{Lib: lib, C_gss_OID: C._GSS_C_NT_USER_NAME} lib.GSS_C_NT_MACHINE_UID_NAME = &OID{Lib: lib, C_gss_OID: C._GSS_C_NT_MACHINE_UID_NAME} lib.GSS_C_NT_STRING_UID_NAME = &OID{Lib: lib, C_gss_OID: C._GSS_C_NT_MACHINE_UID_NAME} lib.GSS_C_NT_HOSTBASED_SERVICE_X = &OID{Lib: lib, C_gss_OID: C._GSS_C_NT_HOSTBASED_SERVICE_X} lib.GSS_C_NT_HOSTBASED_SERVICE = &OID{Lib: lib, C_gss_OID: C._GSS_C_NT_HOSTBASED_SERVICE} lib.GSS_C_NT_ANONYMOUS = &OID{Lib: lib, C_gss_OID: C._GSS_C_NT_ANONYMOUS} lib.GSS_C_NT_EXPORT_NAME = &OID{Lib: lib, C_gss_OID: C._GSS_C_NT_EXPORT_NAME} lib.GSS_KRB5_NT_PRINCIPAL_NAME = &OID{Lib: lib, C_gss_OID: C._GSS_KRB5_NT_PRINCIPAL_NAME} lib.GSS_KRB5_NT_PRINCIPAL = &OID{Lib: lib, C_gss_OID: C._GSS_KRB5_NT_PRINCIPAL} lib.GSS_MECH_KRB5 = &OID{Lib: lib, C_gss_OID: C._GSS_MECH_KRB5} lib.GSS_MECH_KRB5_LEGACY = &OID{Lib: lib, C_gss_OID: C._GSS_MECH_KRB5_LEGACY} lib.GSS_MECH_KRB5_OLD = &OID{Lib: lib, C_gss_OID: C._GSS_MECH_KRB5_OLD} lib.GSS_MECH_SPNEGO = &OID{Lib: lib, C_gss_OID: C._GSS_MECH_SPNEGO} lib.GSS_MECH_IAKERB = &OID{Lib: lib, C_gss_OID: C._GSS_MECH_IAKERB} lib.GSS_MECH_NTLMSSP = &OID{Lib: lib, C_gss_OID: C._GSS_MECH_NTLMSSP} }
go
func (lib *Lib) initConstants() { lib.GSS_C_NO_BUFFER = &Buffer{ Lib: lib, // C_gss_buffer_t: C.GSS_C_NO_BUFFER, already nil // alloc: allocNone, already 0 } lib.GSS_C_NO_OID = lib.NewOID() lib.GSS_C_NO_OID_SET = lib.NewOIDSet() lib.GSS_C_NO_CONTEXT = lib.NewCtxId() lib.GSS_C_NO_CREDENTIAL = lib.NewCredId() lib.GSS_C_NT_USER_NAME = &OID{Lib: lib, C_gss_OID: C._GSS_C_NT_USER_NAME} lib.GSS_C_NT_MACHINE_UID_NAME = &OID{Lib: lib, C_gss_OID: C._GSS_C_NT_MACHINE_UID_NAME} lib.GSS_C_NT_STRING_UID_NAME = &OID{Lib: lib, C_gss_OID: C._GSS_C_NT_MACHINE_UID_NAME} lib.GSS_C_NT_HOSTBASED_SERVICE_X = &OID{Lib: lib, C_gss_OID: C._GSS_C_NT_HOSTBASED_SERVICE_X} lib.GSS_C_NT_HOSTBASED_SERVICE = &OID{Lib: lib, C_gss_OID: C._GSS_C_NT_HOSTBASED_SERVICE} lib.GSS_C_NT_ANONYMOUS = &OID{Lib: lib, C_gss_OID: C._GSS_C_NT_ANONYMOUS} lib.GSS_C_NT_EXPORT_NAME = &OID{Lib: lib, C_gss_OID: C._GSS_C_NT_EXPORT_NAME} lib.GSS_KRB5_NT_PRINCIPAL_NAME = &OID{Lib: lib, C_gss_OID: C._GSS_KRB5_NT_PRINCIPAL_NAME} lib.GSS_KRB5_NT_PRINCIPAL = &OID{Lib: lib, C_gss_OID: C._GSS_KRB5_NT_PRINCIPAL} lib.GSS_MECH_KRB5 = &OID{Lib: lib, C_gss_OID: C._GSS_MECH_KRB5} lib.GSS_MECH_KRB5_LEGACY = &OID{Lib: lib, C_gss_OID: C._GSS_MECH_KRB5_LEGACY} lib.GSS_MECH_KRB5_OLD = &OID{Lib: lib, C_gss_OID: C._GSS_MECH_KRB5_OLD} lib.GSS_MECH_SPNEGO = &OID{Lib: lib, C_gss_OID: C._GSS_MECH_SPNEGO} lib.GSS_MECH_IAKERB = &OID{Lib: lib, C_gss_OID: C._GSS_MECH_IAKERB} lib.GSS_MECH_NTLMSSP = &OID{Lib: lib, C_gss_OID: C._GSS_MECH_NTLMSSP} }
[ "func", "(", "lib", "*", "Lib", ")", "initConstants", "(", ")", "{", "lib", ".", "GSS_C_NO_BUFFER", "=", "&", "Buffer", "{", "Lib", ":", "lib", ",", "// C_gss_buffer_t: C.GSS_C_NO_BUFFER, already nil", "// alloc: allocNone, already 0", "}", "\n", "lib", ".", "GS...
// initConstants sets the initial values of a library's set of 'constants'.
[ "initConstants", "sets", "the", "initial", "values", "of", "a", "library", "s", "set", "of", "constants", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/lib.go#L349-L377
14,960
apcera/gssapi
lib.go
Print
func (lib *Lib) Print(level Severity, a ...interface{}) { if lib == nil || lib.Printers == nil || level >= Severity(len(lib.Printers)) { return } lib.Printers[level].Print(a...) }
go
func (lib *Lib) Print(level Severity, a ...interface{}) { if lib == nil || lib.Printers == nil || level >= Severity(len(lib.Printers)) { return } lib.Printers[level].Print(a...) }
[ "func", "(", "lib", "*", "Lib", ")", "Print", "(", "level", "Severity", ",", "a", "...", "interface", "{", "}", ")", "{", "if", "lib", "==", "nil", "||", "lib", ".", "Printers", "==", "nil", "||", "level", ">=", "Severity", "(", "len", "(", "lib"...
// Print outputs a log line to the specified severity.
[ "Print", "outputs", "a", "log", "line", "to", "the", "specified", "severity", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/lib.go#L380-L385
14,961
apcera/gssapi
credential.go
Release
func (c *CredId) Release() error { if c == nil || c.C_gss_cred_id_t == nil { return nil } min := C.OM_uint32(0) maj := C.wrap_gss_release_cred(c.Fp_gss_release_cred, &min, &c.C_gss_cred_id_t) return c.stashLastStatus(maj, min) }
go
func (c *CredId) Release() error { if c == nil || c.C_gss_cred_id_t == nil { return nil } min := C.OM_uint32(0) maj := C.wrap_gss_release_cred(c.Fp_gss_release_cred, &min, &c.C_gss_cred_id_t) return c.stashLastStatus(maj, min) }
[ "func", "(", "c", "*", "CredId", ")", "Release", "(", ")", "error", "{", "if", "c", "==", "nil", "||", "c", ".", "C_gss_cred_id_t", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "min", ":=", "C", ".", "OM_uint32", "(", "0", ")", "\n", "...
// Release frees a credential.
[ "Release", "frees", "a", "credential", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/credential.go#L296-L307
14,962
apcera/gssapi
buffer.go
MakeBufferBytes
func (lib *Lib) MakeBufferBytes(data []byte) (*Buffer, error) { if len(data) == 0 { return lib.GSS_C_NO_BUFFER, nil } // have to allocate the memory in C land and copy b, err := lib.MakeBuffer(allocMalloc) if err != nil { return nil, err } l := C.size_t(len(data)) c := C.malloc(l) if b == nil { return nil, ErrMallocFailed } C.memmove(c, (unsafe.Pointer)(&data[0]), l) b.C_gss_buffer_t.length = l b.C_gss_buffer_t.value = c b.alloc = allocMalloc return b, nil }
go
func (lib *Lib) MakeBufferBytes(data []byte) (*Buffer, error) { if len(data) == 0 { return lib.GSS_C_NO_BUFFER, nil } // have to allocate the memory in C land and copy b, err := lib.MakeBuffer(allocMalloc) if err != nil { return nil, err } l := C.size_t(len(data)) c := C.malloc(l) if b == nil { return nil, ErrMallocFailed } C.memmove(c, (unsafe.Pointer)(&data[0]), l) b.C_gss_buffer_t.length = l b.C_gss_buffer_t.value = c b.alloc = allocMalloc return b, nil }
[ "func", "(", "lib", "*", "Lib", ")", "MakeBufferBytes", "(", "data", "[", "]", "byte", ")", "(", "*", "Buffer", ",", "error", ")", "{", "if", "len", "(", "data", ")", "==", "0", "{", "return", "lib", ".", "GSS_C_NO_BUFFER", ",", "nil", "\n", "}",...
// MakeBufferBytes makes a Buffer encapsulating a byte slice.
[ "MakeBufferBytes", "makes", "a", "Buffer", "encapsulating", "a", "byte", "slice", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/buffer.go#L82-L105
14,963
apcera/gssapi
buffer.go
MakeBufferString
func (lib *Lib) MakeBufferString(content string) (*Buffer, error) { return lib.MakeBufferBytes([]byte(content)) }
go
func (lib *Lib) MakeBufferString(content string) (*Buffer, error) { return lib.MakeBufferBytes([]byte(content)) }
[ "func", "(", "lib", "*", "Lib", ")", "MakeBufferString", "(", "content", "string", ")", "(", "*", "Buffer", ",", "error", ")", "{", "return", "lib", ".", "MakeBufferBytes", "(", "[", "]", "byte", "(", "content", ")", ")", "\n", "}" ]
// MakeBufferString makes a Buffer encapsulating the contents of a string.
[ "MakeBufferString", "makes", "a", "Buffer", "encapsulating", "the", "contents", "of", "a", "string", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/buffer.go#L108-L110
14,964
apcera/gssapi
buffer.go
Release
func (b *Buffer) Release() error { if b == nil || b.C_gss_buffer_t == nil { return nil } defer func() { C.free(unsafe.Pointer(b.C_gss_buffer_t)) b.C_gss_buffer_t = nil b.alloc = allocNone }() // free the value as needed switch { case b.C_gss_buffer_t.value == nil: // do nothing case b.alloc == allocMalloc: C.free(b.C_gss_buffer_t.value) case b.alloc == allocGSSAPI: var min C.OM_uint32 maj := C.wrap_gss_release_buffer(b.Fp_gss_release_buffer, &min, b.C_gss_buffer_t) err := b.stashLastStatus(maj, min) if err != nil { return err } } return nil }
go
func (b *Buffer) Release() error { if b == nil || b.C_gss_buffer_t == nil { return nil } defer func() { C.free(unsafe.Pointer(b.C_gss_buffer_t)) b.C_gss_buffer_t = nil b.alloc = allocNone }() // free the value as needed switch { case b.C_gss_buffer_t.value == nil: // do nothing case b.alloc == allocMalloc: C.free(b.C_gss_buffer_t.value) case b.alloc == allocGSSAPI: var min C.OM_uint32 maj := C.wrap_gss_release_buffer(b.Fp_gss_release_buffer, &min, b.C_gss_buffer_t) err := b.stashLastStatus(maj, min) if err != nil { return err } } return nil }
[ "func", "(", "b", "*", "Buffer", ")", "Release", "(", ")", "error", "{", "if", "b", "==", "nil", "||", "b", ".", "C_gss_buffer_t", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "defer", "func", "(", ")", "{", "C", ".", "free", "(", "uns...
// Release safely frees the contents of a Buffer.
[ "Release", "safely", "frees", "the", "contents", "of", "a", "Buffer", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/buffer.go#L113-L142
14,965
apcera/gssapi
buffer.go
Length
func (b *Buffer) Length() int { if b == nil || b.C_gss_buffer_t == nil || b.C_gss_buffer_t.length == 0 { return 0 } return int(b.C_gss_buffer_t.length) }
go
func (b *Buffer) Length() int { if b == nil || b.C_gss_buffer_t == nil || b.C_gss_buffer_t.length == 0 { return 0 } return int(b.C_gss_buffer_t.length) }
[ "func", "(", "b", "*", "Buffer", ")", "Length", "(", ")", "int", "{", "if", "b", "==", "nil", "||", "b", ".", "C_gss_buffer_t", "==", "nil", "||", "b", ".", "C_gss_buffer_t", ".", "length", "==", "0", "{", "return", "0", "\n", "}", "\n", "return"...
// Length returns the number of bytes in the Buffer.
[ "Length", "returns", "the", "number", "of", "bytes", "in", "the", "Buffer", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/buffer.go#L145-L150
14,966
apcera/gssapi
buffer.go
Bytes
func (b *Buffer) Bytes() []byte { if b == nil || b.C_gss_buffer_t == nil || b.C_gss_buffer_t.length == 0 { return make([]byte, 0) } return C.GoBytes(b.C_gss_buffer_t.value, C.int(b.C_gss_buffer_t.length)) }
go
func (b *Buffer) Bytes() []byte { if b == nil || b.C_gss_buffer_t == nil || b.C_gss_buffer_t.length == 0 { return make([]byte, 0) } return C.GoBytes(b.C_gss_buffer_t.value, C.int(b.C_gss_buffer_t.length)) }
[ "func", "(", "b", "*", "Buffer", ")", "Bytes", "(", ")", "[", "]", "byte", "{", "if", "b", "==", "nil", "||", "b", ".", "C_gss_buffer_t", "==", "nil", "||", "b", ".", "C_gss_buffer_t", ".", "length", "==", "0", "{", "return", "make", "(", "[", ...
// Bytes returns the contents of a Buffer as a byte slice.
[ "Bytes", "returns", "the", "contents", "of", "a", "Buffer", "as", "a", "byte", "slice", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/buffer.go#L153-L158
14,967
apcera/gssapi
buffer.go
String
func (b *Buffer) String() string { if b == nil || b.C_gss_buffer_t == nil || b.C_gss_buffer_t.length == 0 { return "" } return C.GoStringN((*C.char)(b.C_gss_buffer_t.value), C.int(b.C_gss_buffer_t.length)) }
go
func (b *Buffer) String() string { if b == nil || b.C_gss_buffer_t == nil || b.C_gss_buffer_t.length == 0 { return "" } return C.GoStringN((*C.char)(b.C_gss_buffer_t.value), C.int(b.C_gss_buffer_t.length)) }
[ "func", "(", "b", "*", "Buffer", ")", "String", "(", ")", "string", "{", "if", "b", "==", "nil", "||", "b", ".", "C_gss_buffer_t", "==", "nil", "||", "b", ".", "C_gss_buffer_t", ".", "length", "==", "0", "{", "return", "\"", "\"", "\n", "}", "\n"...
// String returns the contents of a Buffer as a string.
[ "String", "returns", "the", "contents", "of", "a", "Buffer", "as", "a", "string", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/buffer.go#L161-L166
14,968
apcera/gssapi
buffer.go
Equal
func (b *Buffer) Equal(other *Buffer) bool { isEqual := C.wrap_gss_buffer_equal(b.C_gss_buffer_t, other.C_gss_buffer_t) return isEqual != 0 }
go
func (b *Buffer) Equal(other *Buffer) bool { isEqual := C.wrap_gss_buffer_equal(b.C_gss_buffer_t, other.C_gss_buffer_t) return isEqual != 0 }
[ "func", "(", "b", "*", "Buffer", ")", "Equal", "(", "other", "*", "Buffer", ")", "bool", "{", "isEqual", ":=", "C", ".", "wrap_gss_buffer_equal", "(", "b", ".", "C_gss_buffer_t", ",", "other", ".", "C_gss_buffer_t", ")", "\n", "return", "isEqual", "!=", ...
// Equal determines if a Buffer receiver is equivalent to the supplied Buffer.
[ "Equal", "determines", "if", "a", "Buffer", "receiver", "is", "equivalent", "to", "the", "supplied", "Buffer", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/buffer.go#L189-L192
14,969
apcera/gssapi
oid.go
MakeOIDBytes
func (lib *Lib) MakeOIDBytes(data []byte) (*OID, error) { oid := lib.NewOID() s := C.malloc(C.gss_OID_size) // s for struct if s == nil { return nil, ErrMallocFailed } C.memset(s, 0, C.gss_OID_size) l := C.size_t(len(data)) e := C.malloc(l) // c for contents if e == nil { return nil, ErrMallocFailed } C.memmove(e, (unsafe.Pointer)(&data[0]), l) oid.C_gss_OID = C.gss_OID(s) oid.alloc = allocMalloc // because of the alignment issues I can't access o.oid's fields from go, // so invoking a C function to do the same as: // oid.C_gss_OID.length = l // oid.C_gss_OID.elements = c C.helper_gss_OID_desc_set_elements(oid.C_gss_OID, C.OM_uint32(l), e) return oid, nil }
go
func (lib *Lib) MakeOIDBytes(data []byte) (*OID, error) { oid := lib.NewOID() s := C.malloc(C.gss_OID_size) // s for struct if s == nil { return nil, ErrMallocFailed } C.memset(s, 0, C.gss_OID_size) l := C.size_t(len(data)) e := C.malloc(l) // c for contents if e == nil { return nil, ErrMallocFailed } C.memmove(e, (unsafe.Pointer)(&data[0]), l) oid.C_gss_OID = C.gss_OID(s) oid.alloc = allocMalloc // because of the alignment issues I can't access o.oid's fields from go, // so invoking a C function to do the same as: // oid.C_gss_OID.length = l // oid.C_gss_OID.elements = c C.helper_gss_OID_desc_set_elements(oid.C_gss_OID, C.OM_uint32(l), e) return oid, nil }
[ "func", "(", "lib", "*", "Lib", ")", "MakeOIDBytes", "(", "data", "[", "]", "byte", ")", "(", "*", "OID", ",", "error", ")", "{", "oid", ":=", "lib", ".", "NewOID", "(", ")", "\n\n", "s", ":=", "C", ".", "malloc", "(", "C", ".", "gss_OID_size",...
// MakeOIDBytes makes an OID encapsulating a byte slice. Note that it does not // duplicate the data, but rather it points to it directly.
[ "MakeOIDBytes", "makes", "an", "OID", "encapsulating", "a", "byte", "slice", ".", "Note", "that", "it", "does", "not", "duplicate", "the", "data", "but", "rather", "it", "points", "to", "it", "directly", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/oid.go#L49-L75
14,970
apcera/gssapi
oid.go
MakeOIDString
func (lib *Lib) MakeOIDString(data string) (*OID, error) { return lib.MakeOIDBytes([]byte(data)) }
go
func (lib *Lib) MakeOIDString(data string) (*OID, error) { return lib.MakeOIDBytes([]byte(data)) }
[ "func", "(", "lib", "*", "Lib", ")", "MakeOIDString", "(", "data", "string", ")", "(", "*", "OID", ",", "error", ")", "{", "return", "lib", ".", "MakeOIDBytes", "(", "[", "]", "byte", "(", "data", ")", ")", "\n", "}" ]
// MakeOIDString makes an OID from a string.
[ "MakeOIDString", "makes", "an", "OID", "from", "a", "string", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/oid.go#L78-L80
14,971
apcera/gssapi
oid.go
Release
func (oid *OID) Release() error { if oid == nil || oid.C_gss_OID == nil { return nil } switch oid.alloc { case allocMalloc: // same as with get and set, use a C helper to free(oid.C_gss_OID.elements) C.helper_gss_OID_desc_free_elements(oid.C_gss_OID) C.free(unsafe.Pointer(oid.C_gss_OID)) oid.C_gss_OID = nil oid.alloc = allocNone } return nil }
go
func (oid *OID) Release() error { if oid == nil || oid.C_gss_OID == nil { return nil } switch oid.alloc { case allocMalloc: // same as with get and set, use a C helper to free(oid.C_gss_OID.elements) C.helper_gss_OID_desc_free_elements(oid.C_gss_OID) C.free(unsafe.Pointer(oid.C_gss_OID)) oid.C_gss_OID = nil oid.alloc = allocNone } return nil }
[ "func", "(", "oid", "*", "OID", ")", "Release", "(", ")", "error", "{", "if", "oid", "==", "nil", "||", "oid", ".", "C_gss_OID", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "switch", "oid", ".", "alloc", "{", "case", "allocMalloc", ":", ...
// Release safely frees the contents of an OID if it's allocated with malloc by // MakeOIDBytes.
[ "Release", "safely", "frees", "the", "contents", "of", "an", "OID", "if", "it", "s", "allocated", "with", "malloc", "by", "MakeOIDBytes", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/oid.go#L84-L99
14,972
apcera/gssapi
oid.go
Bytes
func (oid OID) Bytes() []byte { var l C.OM_uint32 var p *C.char C.helper_gss_OID_desc_get_elements(oid.C_gss_OID, &l, &p) return C.GoBytes(unsafe.Pointer(p), C.int(l)) }
go
func (oid OID) Bytes() []byte { var l C.OM_uint32 var p *C.char C.helper_gss_OID_desc_get_elements(oid.C_gss_OID, &l, &p) return C.GoBytes(unsafe.Pointer(p), C.int(l)) }
[ "func", "(", "oid", "OID", ")", "Bytes", "(", ")", "[", "]", "byte", "{", "var", "l", "C", ".", "OM_uint32", "\n", "var", "p", "*", "C", ".", "char", "\n\n", "C", ".", "helper_gss_OID_desc_get_elements", "(", "oid", ".", "C_gss_OID", ",", "&", "l",...
// Bytes displays the bytes of an OID.
[ "Bytes", "displays", "the", "bytes", "of", "an", "OID", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/oid.go#L102-L109
14,973
apcera/gssapi
oid.go
String
func (oid *OID) String() string { var l C.OM_uint32 var p *C.char C.helper_gss_OID_desc_get_elements(oid.C_gss_OID, &l, &p) return fmt.Sprintf(`%x`, C.GoStringN(p, C.int(l))) }
go
func (oid *OID) String() string { var l C.OM_uint32 var p *C.char C.helper_gss_OID_desc_get_elements(oid.C_gss_OID, &l, &p) return fmt.Sprintf(`%x`, C.GoStringN(p, C.int(l))) }
[ "func", "(", "oid", "*", "OID", ")", "String", "(", ")", "string", "{", "var", "l", "C", ".", "OM_uint32", "\n", "var", "p", "*", "C", ".", "char", "\n\n", "C", ".", "helper_gss_OID_desc_get_elements", "(", "oid", ".", "C_gss_OID", ",", "&", "l", "...
// String displays a string representation of an OID.
[ "String", "displays", "a", "string", "representation", "of", "an", "OID", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/oid.go#L112-L119
14,974
apcera/gssapi
oid.go
DebugString
func (oid *OID) DebugString() string { switch { case bytes.Equal(oid.Bytes(), oid.GSS_C_NT_USER_NAME.Bytes()): return "GSS_C_NT_USER_NAME" case bytes.Equal(oid.Bytes(), oid.GSS_C_NT_MACHINE_UID_NAME.Bytes()): return "GSS_C_NT_MACHINE_UID_NAME" case bytes.Equal(oid.Bytes(), oid.GSS_C_NT_STRING_UID_NAME.Bytes()): return "GSS_C_NT_STRING_UID_NAME" case bytes.Equal(oid.Bytes(), oid.GSS_C_NT_HOSTBASED_SERVICE_X.Bytes()): return "GSS_C_NT_HOSTBASED_SERVICE_X" case bytes.Equal(oid.Bytes(), oid.GSS_C_NT_HOSTBASED_SERVICE.Bytes()): return "GSS_C_NT_HOSTBASED_SERVICE" case bytes.Equal(oid.Bytes(), oid.GSS_C_NT_ANONYMOUS.Bytes()): return "GSS_C_NT_ANONYMOUS" case bytes.Equal(oid.Bytes(), oid.GSS_C_NT_EXPORT_NAME.Bytes()): return "GSS_C_NT_EXPORT_NAME" case bytes.Equal(oid.Bytes(), oid.GSS_KRB5_NT_PRINCIPAL_NAME.Bytes()): return "GSS_KRB5_NT_PRINCIPAL_NAME" case bytes.Equal(oid.Bytes(), oid.GSS_KRB5_NT_PRINCIPAL.Bytes()): return "GSS_KRB5_NT_PRINCIPAL" case bytes.Equal(oid.Bytes(), oid.GSS_MECH_KRB5.Bytes()): return "GSS_MECH_KRB5" case bytes.Equal(oid.Bytes(), oid.GSS_MECH_KRB5_LEGACY.Bytes()): return "GSS_MECH_KRB5_LEGACY" case bytes.Equal(oid.Bytes(), oid.GSS_MECH_KRB5_OLD.Bytes()): return "GSS_MECH_KRB5_OLD" case bytes.Equal(oid.Bytes(), oid.GSS_MECH_SPNEGO.Bytes()): return "GSS_MECH_SPNEGO" case bytes.Equal(oid.Bytes(), oid.GSS_MECH_IAKERB.Bytes()): return "GSS_MECH_IAKERB" case bytes.Equal(oid.Bytes(), oid.GSS_MECH_NTLMSSP.Bytes()): return "GSS_MECH_NTLMSSP" } return oid.String() }
go
func (oid *OID) DebugString() string { switch { case bytes.Equal(oid.Bytes(), oid.GSS_C_NT_USER_NAME.Bytes()): return "GSS_C_NT_USER_NAME" case bytes.Equal(oid.Bytes(), oid.GSS_C_NT_MACHINE_UID_NAME.Bytes()): return "GSS_C_NT_MACHINE_UID_NAME" case bytes.Equal(oid.Bytes(), oid.GSS_C_NT_STRING_UID_NAME.Bytes()): return "GSS_C_NT_STRING_UID_NAME" case bytes.Equal(oid.Bytes(), oid.GSS_C_NT_HOSTBASED_SERVICE_X.Bytes()): return "GSS_C_NT_HOSTBASED_SERVICE_X" case bytes.Equal(oid.Bytes(), oid.GSS_C_NT_HOSTBASED_SERVICE.Bytes()): return "GSS_C_NT_HOSTBASED_SERVICE" case bytes.Equal(oid.Bytes(), oid.GSS_C_NT_ANONYMOUS.Bytes()): return "GSS_C_NT_ANONYMOUS" case bytes.Equal(oid.Bytes(), oid.GSS_C_NT_EXPORT_NAME.Bytes()): return "GSS_C_NT_EXPORT_NAME" case bytes.Equal(oid.Bytes(), oid.GSS_KRB5_NT_PRINCIPAL_NAME.Bytes()): return "GSS_KRB5_NT_PRINCIPAL_NAME" case bytes.Equal(oid.Bytes(), oid.GSS_KRB5_NT_PRINCIPAL.Bytes()): return "GSS_KRB5_NT_PRINCIPAL" case bytes.Equal(oid.Bytes(), oid.GSS_MECH_KRB5.Bytes()): return "GSS_MECH_KRB5" case bytes.Equal(oid.Bytes(), oid.GSS_MECH_KRB5_LEGACY.Bytes()): return "GSS_MECH_KRB5_LEGACY" case bytes.Equal(oid.Bytes(), oid.GSS_MECH_KRB5_OLD.Bytes()): return "GSS_MECH_KRB5_OLD" case bytes.Equal(oid.Bytes(), oid.GSS_MECH_SPNEGO.Bytes()): return "GSS_MECH_SPNEGO" case bytes.Equal(oid.Bytes(), oid.GSS_MECH_IAKERB.Bytes()): return "GSS_MECH_IAKERB" case bytes.Equal(oid.Bytes(), oid.GSS_MECH_NTLMSSP.Bytes()): return "GSS_MECH_NTLMSSP" } return oid.String() }
[ "func", "(", "oid", "*", "OID", ")", "DebugString", "(", ")", "string", "{", "switch", "{", "case", "bytes", ".", "Equal", "(", "oid", ".", "Bytes", "(", ")", ",", "oid", ".", "GSS_C_NT_USER_NAME", ".", "Bytes", "(", ")", ")", ":", "return", "\"", ...
// Returns a symbolic name for a known OID, or the string. Note that this // function is intended for debugging and is not at all performant.
[ "Returns", "a", "symbolic", "name", "for", "a", "known", "OID", "or", "the", "string", ".", "Note", "that", "this", "function", "is", "intended", "for", "debugging", "and", "is", "not", "at", "all", "performant", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/oid.go#L123-L158
14,975
apcera/gssapi
context.go
AcceptSecContext
func (lib *Lib) AcceptSecContext( ctxIn *CtxId, acceptorCredHandle *CredId, inputToken *Buffer, inputChanBindings ChannelBindings) ( ctxOut *CtxId, srcName *Name, actualMechType *OID, outputToken *Buffer, retFlags uint32, timeRec time.Duration, delegatedCredHandle *CredId, err error) { runtime.LockOSThread() defer runtime.UnlockOSThread() // prepare the inputs C_acceptorCredHandle := C.gss_cred_id_t(nil) if acceptorCredHandle != nil { C_acceptorCredHandle = acceptorCredHandle.C_gss_cred_id_t } C_inputToken := C.gss_buffer_t(nil) if inputToken != nil { C_inputToken = inputToken.C_gss_buffer_t } // prepare the outputs if ctxIn != nil { ctxCopy := *ctxIn ctxOut = &ctxCopy } else { ctxOut = lib.GSS_C_NO_CONTEXT } min := C.OM_uint32(0) srcName = lib.NewName() actualMechType = lib.NewOID() outputToken, err = lib.MakeBuffer(allocGSSAPI) if err != nil { return nil, nil, nil, nil, 0, 0, nil, err } flags := C.OM_uint32(0) timerec := C.OM_uint32(0) delegatedCredHandle = lib.NewCredId() maj := C.wrap_gss_accept_sec_context(lib.Fp_gss_accept_sec_context, &min, &ctxOut.C_gss_ctx_id_t, // used as both in and out param C_acceptorCredHandle, C_inputToken, C.gss_channel_bindings_t(inputChanBindings), &srcName.C_gss_name_t, &actualMechType.C_gss_OID, outputToken.C_gss_buffer_t, &flags, &timerec, &delegatedCredHandle.C_gss_cred_id_t) err = lib.stashLastStatus(maj, min) if err != nil { lib.Err("AcceptSecContext: ", err) return nil, nil, nil, nil, 0, 0, nil, err } if MajorStatus(maj).ContinueNeeded() { err = ErrContinueNeeded } return ctxOut, srcName, actualMechType, outputToken, uint32(flags), time.Duration(timerec) * time.Second, delegatedCredHandle, err }
go
func (lib *Lib) AcceptSecContext( ctxIn *CtxId, acceptorCredHandle *CredId, inputToken *Buffer, inputChanBindings ChannelBindings) ( ctxOut *CtxId, srcName *Name, actualMechType *OID, outputToken *Buffer, retFlags uint32, timeRec time.Duration, delegatedCredHandle *CredId, err error) { runtime.LockOSThread() defer runtime.UnlockOSThread() // prepare the inputs C_acceptorCredHandle := C.gss_cred_id_t(nil) if acceptorCredHandle != nil { C_acceptorCredHandle = acceptorCredHandle.C_gss_cred_id_t } C_inputToken := C.gss_buffer_t(nil) if inputToken != nil { C_inputToken = inputToken.C_gss_buffer_t } // prepare the outputs if ctxIn != nil { ctxCopy := *ctxIn ctxOut = &ctxCopy } else { ctxOut = lib.GSS_C_NO_CONTEXT } min := C.OM_uint32(0) srcName = lib.NewName() actualMechType = lib.NewOID() outputToken, err = lib.MakeBuffer(allocGSSAPI) if err != nil { return nil, nil, nil, nil, 0, 0, nil, err } flags := C.OM_uint32(0) timerec := C.OM_uint32(0) delegatedCredHandle = lib.NewCredId() maj := C.wrap_gss_accept_sec_context(lib.Fp_gss_accept_sec_context, &min, &ctxOut.C_gss_ctx_id_t, // used as both in and out param C_acceptorCredHandle, C_inputToken, C.gss_channel_bindings_t(inputChanBindings), &srcName.C_gss_name_t, &actualMechType.C_gss_OID, outputToken.C_gss_buffer_t, &flags, &timerec, &delegatedCredHandle.C_gss_cred_id_t) err = lib.stashLastStatus(maj, min) if err != nil { lib.Err("AcceptSecContext: ", err) return nil, nil, nil, nil, 0, 0, nil, err } if MajorStatus(maj).ContinueNeeded() { err = ErrContinueNeeded } return ctxOut, srcName, actualMechType, outputToken, uint32(flags), time.Duration(timerec) * time.Second, delegatedCredHandle, err }
[ "func", "(", "lib", "*", "Lib", ")", "AcceptSecContext", "(", "ctxIn", "*", "CtxId", ",", "acceptorCredHandle", "*", "CredId", ",", "inputToken", "*", "Buffer", ",", "inputChanBindings", "ChannelBindings", ")", "(", "ctxOut", "*", "CtxId", ",", "srcName", "*...
// AcceptSecContext accepts an initialized security context. Usually called by // the server. May return ErrContinueNeeded if the client is to make another // iteration of exchanging token with the service
[ "AcceptSecContext", "accepts", "an", "initialized", "security", "context", ".", "Usually", "called", "by", "the", "server", ".", "May", "return", "ErrContinueNeeded", "if", "the", "client", "is", "to", "make", "another", "iteration", "of", "exchanging", "token", ...
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/context.go#L240-L305
14,976
apcera/gssapi
context.go
InquireContext
func (ctx *CtxId) InquireContext() ( srcName *Name, targetName *Name, lifetimeRec time.Duration, mechType *OID, ctxFlags uint64, locallyInitiated bool, open bool, err error) { min := C.OM_uint32(0) srcName = ctx.NewName() targetName = ctx.NewName() rec := C.OM_uint32(0) mechType = ctx.NewOID() flags := C.OM_uint32(0) li := C.int(0) opn := C.int(0) maj := C.wrap_gss_inquire_context(ctx.Fp_gss_inquire_context, &min, ctx.C_gss_ctx_id_t, &srcName.C_gss_name_t, &targetName.C_gss_name_t, &rec, &mechType.C_gss_OID, &flags, &li, &opn) err = ctx.stashLastStatus(maj, min) if err != nil { ctx.Err("InquireContext: ", err) return nil, nil, 0, nil, 0, false, false, err } lifetimeRec = time.Duration(rec) * time.Second ctxFlags = uint64(flags) if li != 0 { locallyInitiated = true } if opn != 0 { open = true } return srcName, targetName, lifetimeRec, mechType, ctxFlags, locallyInitiated, open, nil }
go
func (ctx *CtxId) InquireContext() ( srcName *Name, targetName *Name, lifetimeRec time.Duration, mechType *OID, ctxFlags uint64, locallyInitiated bool, open bool, err error) { min := C.OM_uint32(0) srcName = ctx.NewName() targetName = ctx.NewName() rec := C.OM_uint32(0) mechType = ctx.NewOID() flags := C.OM_uint32(0) li := C.int(0) opn := C.int(0) maj := C.wrap_gss_inquire_context(ctx.Fp_gss_inquire_context, &min, ctx.C_gss_ctx_id_t, &srcName.C_gss_name_t, &targetName.C_gss_name_t, &rec, &mechType.C_gss_OID, &flags, &li, &opn) err = ctx.stashLastStatus(maj, min) if err != nil { ctx.Err("InquireContext: ", err) return nil, nil, 0, nil, 0, false, false, err } lifetimeRec = time.Duration(rec) * time.Second ctxFlags = uint64(flags) if li != 0 { locallyInitiated = true } if opn != 0 { open = true } return srcName, targetName, lifetimeRec, mechType, ctxFlags, locallyInitiated, open, nil }
[ "func", "(", "ctx", "*", "CtxId", ")", "InquireContext", "(", ")", "(", "srcName", "*", "Name", ",", "targetName", "*", "Name", ",", "lifetimeRec", "time", ".", "Duration", ",", "mechType", "*", "OID", ",", "ctxFlags", "uint64", ",", "locallyInitiated", ...
// InquireContext returns fields about a security context.
[ "InquireContext", "returns", "fields", "about", "a", "security", "context", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/context.go#L331-L372
14,977
apcera/gssapi
spnego/spnego_transport.go
AddSPNEGONegotiate
func AddSPNEGONegotiate(h http.Header, name string, token *gssapi.Buffer) { if name == "" { return } v := negotiateScheme if token.Length() != 0 { data := token.Bytes() v = v + " " + base64.StdEncoding.EncodeToString(data) } h.Set(name, v) }
go
func AddSPNEGONegotiate(h http.Header, name string, token *gssapi.Buffer) { if name == "" { return } v := negotiateScheme if token.Length() != 0 { data := token.Bytes() v = v + " " + base64.StdEncoding.EncodeToString(data) } h.Set(name, v) }
[ "func", "AddSPNEGONegotiate", "(", "h", "http", ".", "Header", ",", "name", "string", ",", "token", "*", "gssapi", ".", "Buffer", ")", "{", "if", "name", "==", "\"", "\"", "{", "return", "\n", "}", "\n\n", "v", ":=", "negotiateScheme", "\n", "if", "t...
// AddSPNEGONegotiate adds a Negotiate header with the value of a serialized // token to an http header.
[ "AddSPNEGONegotiate", "adds", "a", "Negotiate", "header", "with", "the", "value", "of", "a", "serialized", "token", "to", "an", "http", "header", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/spnego/spnego_transport.go#L18-L29
14,978
apcera/gssapi
spnego/spnego_transport.go
CheckSPNEGONegotiate
func CheckSPNEGONegotiate(lib *gssapi.Lib, h http.Header, name string) (bool, *gssapi.Buffer) { var err error defer func() { if err != nil { lib.Debug(fmt.Sprintf("CheckSPNEGONegotiate: %v", err)) } }() for _, header := range h[http.CanonicalHeaderKey(name)] { if len(header) < len(negotiateScheme) { continue } if !strings.EqualFold(header[:len(negotiateScheme)], negotiateScheme) { continue } // Remove the "Negotiate" prefix normalizedToken := header[len(negotiateScheme):] // Trim leading and trailing whitespace normalizedToken = strings.TrimSpace(normalizedToken) // Remove internal whitespace (some servers insert whitespace every 76 chars) normalizedToken = strings.Replace(normalizedToken, " ", "", -1) // Pad to a multiple of 4 chars for base64 (some servers strip trailing padding) if unpaddedChars := len(normalizedToken) % 4; unpaddedChars != 0 { normalizedToken += strings.Repeat("=", 4-unpaddedChars) } tbytes, err := base64.StdEncoding.DecodeString(normalizedToken) if err != nil { continue } if len(tbytes) == 0 { return true, nil } token, err := lib.MakeBufferBytes(tbytes) if err != nil { continue } return true, token } return false, nil }
go
func CheckSPNEGONegotiate(lib *gssapi.Lib, h http.Header, name string) (bool, *gssapi.Buffer) { var err error defer func() { if err != nil { lib.Debug(fmt.Sprintf("CheckSPNEGONegotiate: %v", err)) } }() for _, header := range h[http.CanonicalHeaderKey(name)] { if len(header) < len(negotiateScheme) { continue } if !strings.EqualFold(header[:len(negotiateScheme)], negotiateScheme) { continue } // Remove the "Negotiate" prefix normalizedToken := header[len(negotiateScheme):] // Trim leading and trailing whitespace normalizedToken = strings.TrimSpace(normalizedToken) // Remove internal whitespace (some servers insert whitespace every 76 chars) normalizedToken = strings.Replace(normalizedToken, " ", "", -1) // Pad to a multiple of 4 chars for base64 (some servers strip trailing padding) if unpaddedChars := len(normalizedToken) % 4; unpaddedChars != 0 { normalizedToken += strings.Repeat("=", 4-unpaddedChars) } tbytes, err := base64.StdEncoding.DecodeString(normalizedToken) if err != nil { continue } if len(tbytes) == 0 { return true, nil } token, err := lib.MakeBufferBytes(tbytes) if err != nil { continue } return true, token } return false, nil }
[ "func", "CheckSPNEGONegotiate", "(", "lib", "*", "gssapi", ".", "Lib", ",", "h", "http", ".", "Header", ",", "name", "string", ")", "(", "bool", ",", "*", "gssapi", ".", "Buffer", ")", "{", "var", "err", "error", "\n", "defer", "func", "(", ")", "{...
// CheckSPNEGONegotiate checks for the presence of a Negotiate header. If // present, we return a gssapi Token created from the header value sent to us.
[ "CheckSPNEGONegotiate", "checks", "for", "the", "presence", "of", "a", "Negotiate", "header", ".", "If", "present", "we", "return", "a", "gssapi", "Token", "created", "from", "the", "header", "value", "sent", "to", "us", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/spnego/spnego_transport.go#L33-L77
14,979
apcera/gssapi
name.go
Release
func (n *Name) Release() error { if n == nil || n.C_gss_name_t == nil { return nil } var min C.OM_uint32 maj := C.wrap_gss_release_name(n.Fp_gss_release_name, &min, &n.C_gss_name_t) err := n.stashLastStatus(maj, min) if err == nil { n.C_gss_name_t = nil } return err }
go
func (n *Name) Release() error { if n == nil || n.C_gss_name_t == nil { return nil } var min C.OM_uint32 maj := C.wrap_gss_release_name(n.Fp_gss_release_name, &min, &n.C_gss_name_t) err := n.stashLastStatus(maj, min) if err == nil { n.C_gss_name_t = nil } return err }
[ "func", "(", "n", "*", "Name", ")", "Release", "(", ")", "error", "{", "if", "n", "==", "nil", "||", "n", ".", "C_gss_name_t", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "var", "min", "C", ".", "OM_uint32", "\n", "maj", ":=", "C", "....
// Release frees the memory associated with an internal representation of the // name.
[ "Release", "frees", "the", "memory", "associated", "with", "an", "internal", "representation", "of", "the", "name", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/name.go#L146-L158
14,980
apcera/gssapi
name.go
Display
func (n Name) Display() (name string, oid *OID, err error) { var min C.OM_uint32 b, err := n.MakeBuffer(allocGSSAPI) if err != nil { return "", nil, err } defer b.Release() oid = n.NewOID() maj := C.wrap_gss_display_name(n.Fp_gss_display_name, &min, n.C_gss_name_t, b.C_gss_buffer_t, &oid.C_gss_OID) err = n.stashLastStatus(maj, min) if err != nil { oid.Release() return "", nil, err } return b.String(), oid, err }
go
func (n Name) Display() (name string, oid *OID, err error) { var min C.OM_uint32 b, err := n.MakeBuffer(allocGSSAPI) if err != nil { return "", nil, err } defer b.Release() oid = n.NewOID() maj := C.wrap_gss_display_name(n.Fp_gss_display_name, &min, n.C_gss_name_t, b.C_gss_buffer_t, &oid.C_gss_OID) err = n.stashLastStatus(maj, min) if err != nil { oid.Release() return "", nil, err } return b.String(), oid, err }
[ "func", "(", "n", "Name", ")", "Display", "(", ")", "(", "name", "string", ",", "oid", "*", "OID", ",", "err", "error", ")", "{", "var", "min", "C", ".", "OM_uint32", "\n", "b", ",", "err", ":=", "n", ".", "MakeBuffer", "(", "allocGSSAPI", ")", ...
// Display "allows an application to obtain a textual representation of an // opaque internal-form name for display purposes"
[ "Display", "allows", "an", "application", "to", "obtain", "a", "textual", "representation", "of", "an", "opaque", "internal", "-", "form", "name", "for", "display", "purposes" ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/name.go#L177-L197
14,981
apcera/gssapi
name.go
Canonicalize
func (n Name) Canonicalize(mech_type *OID) (canonical *Name, err error) { canonical = &Name{ Lib: n.Lib, } var min C.OM_uint32 maj := C.wrap_gss_canonicalize_name(n.Fp_gss_canonicalize_name, &min, n.C_gss_name_t, mech_type.C_gss_OID, &canonical.C_gss_name_t) err = n.stashLastStatus(maj, min) if err != nil { return nil, err } return canonical, nil }
go
func (n Name) Canonicalize(mech_type *OID) (canonical *Name, err error) { canonical = &Name{ Lib: n.Lib, } var min C.OM_uint32 maj := C.wrap_gss_canonicalize_name(n.Fp_gss_canonicalize_name, &min, n.C_gss_name_t, mech_type.C_gss_OID, &canonical.C_gss_name_t) err = n.stashLastStatus(maj, min) if err != nil { return nil, err } return canonical, nil }
[ "func", "(", "n", "Name", ")", "Canonicalize", "(", "mech_type", "*", "OID", ")", "(", "canonical", "*", "Name", ",", "err", "error", ")", "{", "canonical", "=", "&", "Name", "{", "Lib", ":", "n", ".", "Lib", ",", "}", "\n\n", "var", "min", "C", ...
// Canonicalize returns a copy of this name, canonicalized for the specified // mechanism
[ "Canonicalize", "returns", "a", "copy", "of", "this", "name", "canonicalized", "for", "the", "specified", "mechanism" ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/name.go#L207-L221
14,982
apcera/gssapi
name.go
InquireMechs
func (n *Name) InquireMechs() (oids *OIDSet, err error) { oidset := n.NewOIDSet() if err != nil { return nil, err } var min C.OM_uint32 maj := C.wrap_gss_inquire_mechs_for_name(n.Fp_gss_inquire_mechs_for_name, &min, n.C_gss_name_t, &oidset.C_gss_OID_set) err = n.stashLastStatus(maj, min) if err != nil { return nil, err } return oidset, nil }
go
func (n *Name) InquireMechs() (oids *OIDSet, err error) { oidset := n.NewOIDSet() if err != nil { return nil, err } var min C.OM_uint32 maj := C.wrap_gss_inquire_mechs_for_name(n.Fp_gss_inquire_mechs_for_name, &min, n.C_gss_name_t, &oidset.C_gss_OID_set) err = n.stashLastStatus(maj, min) if err != nil { return nil, err } return oidset, nil }
[ "func", "(", "n", "*", "Name", ")", "InquireMechs", "(", ")", "(", "oids", "*", "OIDSet", ",", "err", "error", ")", "{", "oidset", ":=", "n", ".", "NewOIDSet", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}...
// InquireMechs returns the set of mechanisms supported by the GSS-API // implementation that may be able to process the specified name
[ "InquireMechs", "returns", "the", "set", "of", "mechanisms", "supported", "by", "the", "GSS", "-", "API", "implementation", "that", "may", "be", "able", "to", "process", "the", "specified", "name" ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/name.go#L262-L277
14,983
apcera/gssapi
name.go
InquireNamesForMechs
func (lib *Lib) InquireNamesForMechs(mech *OID) (name_types *OIDSet, err error) { oidset := lib.NewOIDSet() if err != nil { return nil, err } var min C.OM_uint32 maj := C.wrap_gss_inquire_names_for_mech(lib.Fp_gss_inquire_mechs_for_name, &min, mech.C_gss_OID, &oidset.C_gss_OID_set) err = lib.stashLastStatus(maj, min) if err != nil { return nil, err } return oidset, nil }
go
func (lib *Lib) InquireNamesForMechs(mech *OID) (name_types *OIDSet, err error) { oidset := lib.NewOIDSet() if err != nil { return nil, err } var min C.OM_uint32 maj := C.wrap_gss_inquire_names_for_mech(lib.Fp_gss_inquire_mechs_for_name, &min, mech.C_gss_OID, &oidset.C_gss_OID_set) err = lib.stashLastStatus(maj, min) if err != nil { return nil, err } return oidset, nil }
[ "func", "(", "lib", "*", "Lib", ")", "InquireNamesForMechs", "(", "mech", "*", "OID", ")", "(", "name_types", "*", "OIDSet", ",", "err", "error", ")", "{", "oidset", ":=", "lib", ".", "NewOIDSet", "(", ")", "\n", "if", "err", "!=", "nil", "{", "ret...
// InquireNameForMech returns the set of name types supported by // the specified mechanism
[ "InquireNameForMech", "returns", "the", "set", "of", "name", "types", "supported", "by", "the", "specified", "mechanism" ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/name.go#L281-L296
14,984
apcera/gssapi
status.go
MakeError
func (lib *Lib) MakeError(major, minor C.OM_uint32) *Error { return &Error{ Lib: lib, Major: MajorStatus(major), Minor: minor, } }
go
func (lib *Lib) MakeError(major, minor C.OM_uint32) *Error { return &Error{ Lib: lib, Major: MajorStatus(major), Minor: minor, } }
[ "func", "(", "lib", "*", "Lib", ")", "MakeError", "(", "major", ",", "minor", "C", ".", "OM_uint32", ")", "*", "Error", "{", "return", "&", "Error", "{", "Lib", ":", "lib", ",", "Major", ":", "MajorStatus", "(", "major", ")", ",", "Minor", ":", "...
// MakeError creates a golang Error object from a gssapi major & minor status.
[ "MakeError", "creates", "a", "golang", "Error", "object", "from", "a", "gssapi", "major", "&", "minor", "status", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/status.go#L174-L180
14,985
apcera/gssapi
status.go
Error
func (e *Error) Error() string { messages := []string{} nOther := 0 context := C.OM_uint32(0) inquiry := C.OM_uint32(0) code_type := 0 first := true if e.Major.RoutineError() == GSS_S_FAILURE { inquiry = e.Minor code_type = GSS_C_MECH_CODE } else { inquiry = C.OM_uint32(e.Major) code_type = GSS_C_GSS_CODE } for first || context != C.OM_uint32(0) { first = false min := C.OM_uint32(0) b, err := e.MakeBuffer(allocGSSAPI) if err != nil { break } // TODO: store a mech_type at the lib level? Or context? For now GSS_C_NO_OID... maj := C.wrap_gss_display_status( e.Fp_gss_display_status, &min, inquiry, C.int(code_type), nil, &context, b.C_gss_buffer_t) err = e.MakeError(maj, min).GoError() if err != nil { nOther = nOther + 1 } messages = append(messages, b.String()) b.Release() } if nOther > 0 { messages = append(messages, fmt.Sprintf("additionally, %d conversions failed", nOther)) } messages = append(messages, "") return strings.Join(messages, "\n") }
go
func (e *Error) Error() string { messages := []string{} nOther := 0 context := C.OM_uint32(0) inquiry := C.OM_uint32(0) code_type := 0 first := true if e.Major.RoutineError() == GSS_S_FAILURE { inquiry = e.Minor code_type = GSS_C_MECH_CODE } else { inquiry = C.OM_uint32(e.Major) code_type = GSS_C_GSS_CODE } for first || context != C.OM_uint32(0) { first = false min := C.OM_uint32(0) b, err := e.MakeBuffer(allocGSSAPI) if err != nil { break } // TODO: store a mech_type at the lib level? Or context? For now GSS_C_NO_OID... maj := C.wrap_gss_display_status( e.Fp_gss_display_status, &min, inquiry, C.int(code_type), nil, &context, b.C_gss_buffer_t) err = e.MakeError(maj, min).GoError() if err != nil { nOther = nOther + 1 } messages = append(messages, b.String()) b.Release() } if nOther > 0 { messages = append(messages, fmt.Sprintf("additionally, %d conversions failed", nOther)) } messages = append(messages, "") return strings.Join(messages, "\n") }
[ "func", "(", "e", "*", "Error", ")", "Error", "(", ")", "string", "{", "messages", ":=", "[", "]", "string", "{", "}", "\n", "nOther", ":=", "0", "\n", "context", ":=", "C", ".", "OM_uint32", "(", "0", ")", "\n", "inquiry", ":=", "C", ".", "OM_...
// Error returns a string representation of an Error object.
[ "Error", "returns", "a", "string", "representation", "of", "an", "Error", "object", "." ]
5fb4217df13b8e6878046fe1e5c10e560e1b86dc
https://github.com/apcera/gssapi/blob/5fb4217df13b8e6878046fe1e5c10e560e1b86dc/status.go#L200-L247
14,986
bradleyjkemp/memviz
memviz.go
Map
func Map(w io.Writer, is ...interface{}) { var iVals []reflect.Value for _, i := range is { iVal := reflect.ValueOf(i) if !iVal.CanAddr() { if iVal.Kind() != reflect.Ptr && iVal.Kind() != reflect.Interface { fmt.Fprint(w, "error: cannot map unaddressable value") return } iVal = iVal.Elem() } iVals = append(iVals, iVal) } m := &mapper{ w, map[nodeKey]nodeID{nilKey: 0}, map[nodeKey]string{nilKey: "nil"}, 2, } fmt.Fprintln(w, "digraph structs {") fmt.Fprintln(w, " node [shape=Mrecord];") for _, iVal := range iVals { m.mapValue(iVal, 0, false) } fmt.Fprintln(w, "}") }
go
func Map(w io.Writer, is ...interface{}) { var iVals []reflect.Value for _, i := range is { iVal := reflect.ValueOf(i) if !iVal.CanAddr() { if iVal.Kind() != reflect.Ptr && iVal.Kind() != reflect.Interface { fmt.Fprint(w, "error: cannot map unaddressable value") return } iVal = iVal.Elem() } iVals = append(iVals, iVal) } m := &mapper{ w, map[nodeKey]nodeID{nilKey: 0}, map[nodeKey]string{nilKey: "nil"}, 2, } fmt.Fprintln(w, "digraph structs {") fmt.Fprintln(w, " node [shape=Mrecord];") for _, iVal := range iVals { m.mapValue(iVal, 0, false) } fmt.Fprintln(w, "}") }
[ "func", "Map", "(", "w", "io", ".", "Writer", ",", "is", "...", "interface", "{", "}", ")", "{", "var", "iVals", "[", "]", "reflect", ".", "Value", "\n", "for", "_", ",", "i", ":=", "range", "is", "{", "iVal", ":=", "reflect", ".", "ValueOf", "...
// Map prints out a Graphviz digraph of the given datastructure to the given io.Writer
[ "Map", "prints", "out", "a", "Graphviz", "digraph", "of", "the", "given", "datastructure", "to", "the", "given", "io", ".", "Writer" ]
4dc768b3c2246ec3ee2c15642ffc2d8ce8fa4d9d
https://github.com/bradleyjkemp/memviz/blob/4dc768b3c2246ec3ee2c15642ffc2d8ce8fa4d9d/memviz.go#L32-L60
14,987
antchfx/xpath
parse.go
newOperatorNode
func newOperatorNode(op string, left, right node) node { return &operatorNode{nodeType: nodeOperator, Op: op, Left: left, Right: right} }
go
func newOperatorNode(op string, left, right node) node { return &operatorNode{nodeType: nodeOperator, Op: op, Left: left, Right: right} }
[ "func", "newOperatorNode", "(", "op", "string", ",", "left", ",", "right", "node", ")", "node", "{", "return", "&", "operatorNode", "{", "nodeType", ":", "nodeOperator", ",", "Op", ":", "op", ",", "Left", ":", "left", ",", "Right", ":", "right", "}", ...
// newOperatorNode returns new operator node OperatorNode.
[ "newOperatorNode", "returns", "new", "operator", "node", "OperatorNode", "." ]
ce1d48779e67a1ddfb380995fe532b2e0015919c
https://github.com/antchfx/xpath/blob/ce1d48779e67a1ddfb380995fe532b2e0015919c/parse.go#L76-L78
14,988
antchfx/xpath
parse.go
newAxisNode
func newAxisNode(axeTyp, localName, prefix, prop string, n node) node { return &axisNode{ nodeType: nodeAxis, LocalName: localName, Prefix: prefix, AxeType: axeTyp, Prop: prop, Input: n, } }
go
func newAxisNode(axeTyp, localName, prefix, prop string, n node) node { return &axisNode{ nodeType: nodeAxis, LocalName: localName, Prefix: prefix, AxeType: axeTyp, Prop: prop, Input: n, } }
[ "func", "newAxisNode", "(", "axeTyp", ",", "localName", ",", "prefix", ",", "prop", "string", ",", "n", "node", ")", "node", "{", "return", "&", "axisNode", "{", "nodeType", ":", "nodeAxis", ",", "LocalName", ":", "localName", ",", "Prefix", ":", "prefix...
// newAxisNode returns new axis node AxisNode.
[ "newAxisNode", "returns", "new", "axis", "node", "AxisNode", "." ]
ce1d48779e67a1ddfb380995fe532b2e0015919c
https://github.com/antchfx/xpath/blob/ce1d48779e67a1ddfb380995fe532b2e0015919c/parse.go#L86-L95
14,989
antchfx/xpath
parse.go
newVariableNode
func newVariableNode(prefix, name string) node { return &variableNode{nodeType: nodeVariable, Name: name, Prefix: prefix} }
go
func newVariableNode(prefix, name string) node { return &variableNode{nodeType: nodeVariable, Name: name, Prefix: prefix} }
[ "func", "newVariableNode", "(", "prefix", ",", "name", "string", ")", "node", "{", "return", "&", "variableNode", "{", "nodeType", ":", "nodeVariable", ",", "Name", ":", "name", ",", "Prefix", ":", "prefix", "}", "\n", "}" ]
// newVariableNode returns new variable node VariableNode.
[ "newVariableNode", "returns", "new", "variable", "node", "VariableNode", "." ]
ce1d48779e67a1ddfb380995fe532b2e0015919c
https://github.com/antchfx/xpath/blob/ce1d48779e67a1ddfb380995fe532b2e0015919c/parse.go#L98-L100
14,990
antchfx/xpath
parse.go
newFilterNode
func newFilterNode(n, m node) node { return &filterNode{nodeType: nodeFilter, Input: n, Condition: m} }
go
func newFilterNode(n, m node) node { return &filterNode{nodeType: nodeFilter, Input: n, Condition: m} }
[ "func", "newFilterNode", "(", "n", ",", "m", "node", ")", "node", "{", "return", "&", "filterNode", "{", "nodeType", ":", "nodeFilter", ",", "Input", ":", "n", ",", "Condition", ":", "m", "}", "\n", "}" ]
// newFilterNode returns a new filter node FilterNode.
[ "newFilterNode", "returns", "a", "new", "filter", "node", "FilterNode", "." ]
ce1d48779e67a1ddfb380995fe532b2e0015919c
https://github.com/antchfx/xpath/blob/ce1d48779e67a1ddfb380995fe532b2e0015919c/parse.go#L103-L105
14,991
antchfx/xpath
parse.go
newFunctionNode
func newFunctionNode(name, prefix string, args []node) node { return &functionNode{nodeType: nodeFunction, Prefix: prefix, FuncName: name, Args: args} }
go
func newFunctionNode(name, prefix string, args []node) node { return &functionNode{nodeType: nodeFunction, Prefix: prefix, FuncName: name, Args: args} }
[ "func", "newFunctionNode", "(", "name", ",", "prefix", "string", ",", "args", "[", "]", "node", ")", "node", "{", "return", "&", "functionNode", "{", "nodeType", ":", "nodeFunction", ",", "Prefix", ":", "prefix", ",", "FuncName", ":", "name", ",", "Args"...
// newFunctionNode returns function call node.
[ "newFunctionNode", "returns", "function", "call", "node", "." ]
ce1d48779e67a1ddfb380995fe532b2e0015919c
https://github.com/antchfx/xpath/blob/ce1d48779e67a1ddfb380995fe532b2e0015919c/parse.go#L113-L115
14,992
antchfx/xpath
parse.go
parseExpression
func (p *parser) parseExpression(n node) node { if p.d = p.d + 1; p.d > 200 { panic("the xpath query is too complex(depth > 200)") } n = p.parseOrExpr(n) p.d-- return n }
go
func (p *parser) parseExpression(n node) node { if p.d = p.d + 1; p.d > 200 { panic("the xpath query is too complex(depth > 200)") } n = p.parseOrExpr(n) p.d-- return n }
[ "func", "(", "p", "*", "parser", ")", "parseExpression", "(", "n", "node", ")", "node", "{", "if", "p", ".", "d", "=", "p", ".", "d", "+", "1", ";", "p", ".", "d", ">", "200", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "n", "=",...
// parseExpression parsing the expression with input node n.
[ "parseExpression", "parsing", "the", "expression", "with", "input", "node", "n", "." ]
ce1d48779e67a1ddfb380995fe532b2e0015919c
https://github.com/antchfx/xpath/blob/ce1d48779e67a1ddfb380995fe532b2e0015919c/parse.go#L155-L162
14,993
antchfx/xpath
parse.go
parse
func parse(expr string) node { r := &scanner{text: expr} r.nextChar() r.nextItem() p := &parser{r: r} return p.parseExpression(nil) }
go
func parse(expr string) node { r := &scanner{text: expr} r.nextChar() r.nextItem() p := &parser{r: r} return p.parseExpression(nil) }
[ "func", "parse", "(", "expr", "string", ")", "node", "{", "r", ":=", "&", "scanner", "{", "text", ":", "expr", "}", "\n", "r", ".", "nextChar", "(", ")", "\n", "r", ".", "nextItem", "(", ")", "\n", "p", ":=", "&", "parser", "{", "r", ":", "r"...
// Parse parsing the XPath express string expr and returns a tree node.
[ "Parse", "parsing", "the", "XPath", "express", "string", "expr", "and", "returns", "a", "tree", "node", "." ]
ce1d48779e67a1ddfb380995fe532b2e0015919c
https://github.com/antchfx/xpath/blob/ce1d48779e67a1ddfb380995fe532b2e0015919c/parse.go#L526-L532
14,994
antchfx/xpath
operator.go
cmpNumberNumberF
func cmpNumberNumberF(op string, a, b float64) bool { switch op { case "=": return a == b case ">": return a > b case "<": return a < b case ">=": return a >= b case "<=": return a <= b case "!=": return a != b } return false }
go
func cmpNumberNumberF(op string, a, b float64) bool { switch op { case "=": return a == b case ">": return a > b case "<": return a < b case ">=": return a >= b case "<=": return a <= b case "!=": return a != b } return false }
[ "func", "cmpNumberNumberF", "(", "op", "string", ",", "a", ",", "b", "float64", ")", "bool", "{", "switch", "op", "{", "case", "\"", "\"", ":", "return", "a", "==", "b", "\n", "case", "\"", "\"", ":", "return", "a", ">", "b", "\n", "case", "\"", ...
// number vs number
[ "number", "vs", "number" ]
ce1d48779e67a1ddfb380995fe532b2e0015919c
https://github.com/antchfx/xpath/blob/ce1d48779e67a1ddfb380995fe532b2e0015919c/operator.go#L48-L64
14,995
antchfx/xpath
operator.go
cmpStringStringF
func cmpStringStringF(op string, a, b string) bool { switch op { case "=": return a == b case ">": return a > b case "<": return a < b case ">=": return a >= b case "<=": return a <= b case "!=": return a != b } return false }
go
func cmpStringStringF(op string, a, b string) bool { switch op { case "=": return a == b case ">": return a > b case "<": return a < b case ">=": return a >= b case "<=": return a <= b case "!=": return a != b } return false }
[ "func", "cmpStringStringF", "(", "op", "string", ",", "a", ",", "b", "string", ")", "bool", "{", "switch", "op", "{", "case", "\"", "\"", ":", "return", "a", "==", "b", "\n", "case", "\"", "\"", ":", "return", "a", ">", "b", "\n", "case", "\"", ...
// string vs string
[ "string", "vs", "string" ]
ce1d48779e67a1ddfb380995fe532b2e0015919c
https://github.com/antchfx/xpath/blob/ce1d48779e67a1ddfb380995fe532b2e0015919c/operator.go#L67-L83
14,996
antchfx/xpath
operator.go
eqFunc
func eqFunc(t iterator, m, n interface{}) interface{} { t1 := getValueType(m) t2 := getValueType(n) return logicalFuncs[t1][t2](t, "=", m, n) }
go
func eqFunc(t iterator, m, n interface{}) interface{} { t1 := getValueType(m) t2 := getValueType(n) return logicalFuncs[t1][t2](t, "=", m, n) }
[ "func", "eqFunc", "(", "t", "iterator", ",", "m", ",", "n", "interface", "{", "}", ")", "interface", "{", "}", "{", "t1", ":=", "getValueType", "(", "m", ")", "\n", "t2", ":=", "getValueType", "(", "n", ")", "\n", "return", "logicalFuncs", "[", "t1...
// eqFunc is an `=` operator.
[ "eqFunc", "is", "an", "=", "operator", "." ]
ce1d48779e67a1ddfb380995fe532b2e0015919c
https://github.com/antchfx/xpath/blob/ce1d48779e67a1ddfb380995fe532b2e0015919c/operator.go#L207-L211
14,997
antchfx/xpath
build.go
axisPredicate
func axisPredicate(root *axisNode) func(NodeNavigator) bool { // get current axix node type. typ := ElementNode switch root.AxeType { case "attribute": typ = AttributeNode case "self", "parent": typ = allNode default: switch root.Prop { case "comment": typ = CommentNode case "text": typ = TextNode // case "processing-instruction": // typ = ProcessingInstructionNode case "node": typ = allNode } } nametest := root.LocalName != "" || root.Prefix != "" predicate := func(n NodeNavigator) bool { if typ == n.NodeType() || typ == allNode || typ == TextNode { if nametest { if root.LocalName == n.LocalName() && root.Prefix == n.Prefix() { return true } } else { return true } } return false } return predicate }
go
func axisPredicate(root *axisNode) func(NodeNavigator) bool { // get current axix node type. typ := ElementNode switch root.AxeType { case "attribute": typ = AttributeNode case "self", "parent": typ = allNode default: switch root.Prop { case "comment": typ = CommentNode case "text": typ = TextNode // case "processing-instruction": // typ = ProcessingInstructionNode case "node": typ = allNode } } nametest := root.LocalName != "" || root.Prefix != "" predicate := func(n NodeNavigator) bool { if typ == n.NodeType() || typ == allNode || typ == TextNode { if nametest { if root.LocalName == n.LocalName() && root.Prefix == n.Prefix() { return true } } else { return true } } return false } return predicate }
[ "func", "axisPredicate", "(", "root", "*", "axisNode", ")", "func", "(", "NodeNavigator", ")", "bool", "{", "// get current axix node type.", "typ", ":=", "ElementNode", "\n", "switch", "root", ".", "AxeType", "{", "case", "\"", "\"", ":", "typ", "=", "Attri...
// axisPredicate creates a predicate to predicating for this axis node.
[ "axisPredicate", "creates", "a", "predicate", "to", "predicating", "for", "this", "axis", "node", "." ]
ce1d48779e67a1ddfb380995fe532b2e0015919c
https://github.com/antchfx/xpath/blob/ce1d48779e67a1ddfb380995fe532b2e0015919c/build.go#L23-L58
14,998
antchfx/xpath
build.go
processFilterNode
func (b *builder) processFilterNode(root *filterNode) (query, error) { b.flag |= filterFlag qyInput, err := b.processNode(root.Input) if err != nil { return nil, err } qyCond, err := b.processNode(root.Condition) if err != nil { return nil, err } qyOutput := &filterQuery{Input: qyInput, Predicate: qyCond} return qyOutput, nil }
go
func (b *builder) processFilterNode(root *filterNode) (query, error) { b.flag |= filterFlag qyInput, err := b.processNode(root.Input) if err != nil { return nil, err } qyCond, err := b.processNode(root.Condition) if err != nil { return nil, err } qyOutput := &filterQuery{Input: qyInput, Predicate: qyCond} return qyOutput, nil }
[ "func", "(", "b", "*", "builder", ")", "processFilterNode", "(", "root", "*", "filterNode", ")", "(", "query", ",", "error", ")", "{", "b", ".", "flag", "|=", "filterFlag", "\n\n", "qyInput", ",", "err", ":=", "b", ".", "processNode", "(", "root", "....
// processFilterNode builds query for the XPath filter predicate.
[ "processFilterNode", "builds", "query", "for", "the", "XPath", "filter", "predicate", "." ]
ce1d48779e67a1ddfb380995fe532b2e0015919c
https://github.com/antchfx/xpath/blob/ce1d48779e67a1ddfb380995fe532b2e0015919c/build.go#L137-L150
14,999
antchfx/xpath
build.go
build
func build(expr string) (q query, err error) { defer func() { if e := recover(); e != nil { switch x := e.(type) { case string: err = errors.New(x) case error: err = x default: err = errors.New("unknown panic") } } }() root := parse(expr) b := &builder{} return b.processNode(root) }
go
func build(expr string) (q query, err error) { defer func() { if e := recover(); e != nil { switch x := e.(type) { case string: err = errors.New(x) case error: err = x default: err = errors.New("unknown panic") } } }() root := parse(expr) b := &builder{} return b.processNode(root) }
[ "func", "build", "(", "expr", "string", ")", "(", "q", "query", ",", "err", "error", ")", "{", "defer", "func", "(", ")", "{", "if", "e", ":=", "recover", "(", ")", ";", "e", "!=", "nil", "{", "switch", "x", ":=", "e", ".", "(", "type", ")", ...
// build builds a specified XPath expressions expr.
[ "build", "builds", "a", "specified", "XPath", "expressions", "expr", "." ]
ce1d48779e67a1ddfb380995fe532b2e0015919c
https://github.com/antchfx/xpath/blob/ce1d48779e67a1ddfb380995fe532b2e0015919c/build.go#L467-L483