id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
30,400 | cdipaolo/goml | cluster/triangle_kmeans.go | SaveClusteredData | func (k *TriangleKMeans) SaveClusteredData(filepath string) error {
floatGuesses := []float64{}
for _, val := range k.guesses {
floatGuesses = append(floatGuesses, float64(val))
}
return base.SaveDataToCSV(filepath, k.trainingSet, floatGuesses, true)
} | go | func (k *TriangleKMeans) SaveClusteredData(filepath string) error {
floatGuesses := []float64{}
for _, val := range k.guesses {
floatGuesses = append(floatGuesses, float64(val))
}
return base.SaveDataToCSV(filepath, k.trainingSet, floatGuesses, true)
} | [
"func",
"(",
"k",
"*",
"TriangleKMeans",
")",
"SaveClusteredData",
"(",
"filepath",
"string",
")",
"error",
"{",
"floatGuesses",
":=",
"[",
"]",
"float64",
"{",
"}",
"\n",
"for",
"_",
",",
"val",
":=",
"range",
"k",
".",
"guesses",
"{",
"floatGuesses",
... | // SaveClusteredData takes operates on a k-means
// model, concatenating the given dataset with the
// assigned class from clustering and saving it to
// file.
//
// Basically just a wrapper for the base.SaveDataToCSV
// with the K-Means data. | [
"SaveClusteredData",
"takes",
"operates",
"on",
"a",
"k",
"-",
"means",
"model",
"concatenating",
"the",
"given",
"dataset",
"with",
"the",
"assigned",
"class",
"from",
"clustering",
"and",
"saving",
"it",
"to",
"file",
".",
"Basically",
"just",
"a",
"wrapper"... | e1f51f7135988cf33ef5feafa6d1558e4f28d981 | https://github.com/cdipaolo/goml/blob/e1f51f7135988cf33ef5feafa6d1558e4f28d981/cluster/triangle_kmeans.go#L588-L595 |
30,401 | cdipaolo/goml | linear/linear.go | Learn | func (l *LeastSquares) Learn() error {
if l.trainingSet == nil || l.expectedResults == nil {
err := fmt.Errorf("ERROR: Attempting to learn with no training examples!\n")
fmt.Fprintf(l.Output, err.Error())
return err
}
examples := len(l.trainingSet)
if examples == 0 || len(l.trainingSet[0]) == 0 {
err := fm... | go | func (l *LeastSquares) Learn() error {
if l.trainingSet == nil || l.expectedResults == nil {
err := fmt.Errorf("ERROR: Attempting to learn with no training examples!\n")
fmt.Fprintf(l.Output, err.Error())
return err
}
examples := len(l.trainingSet)
if examples == 0 || len(l.trainingSet[0]) == 0 {
err := fm... | [
"func",
"(",
"l",
"*",
"LeastSquares",
")",
"Learn",
"(",
")",
"error",
"{",
"if",
"l",
".",
"trainingSet",
"==",
"nil",
"||",
"l",
".",
"expectedResults",
"==",
"nil",
"{",
"err",
":=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
")",
"\n",
"f... | // Learn takes the struct's dataset and expected results and runs
// batch gradient descent on them, optimizing theta so you can
// predict based on those results | [
"Learn",
"takes",
"the",
"struct",
"s",
"dataset",
"and",
"expected",
"results",
"and",
"runs",
"batch",
"gradient",
"descent",
"on",
"them",
"optimizing",
"theta",
"so",
"you",
"can",
"predict",
"based",
"on",
"those",
"results"
] | e1f51f7135988cf33ef5feafa6d1558e4f28d981 | https://github.com/cdipaolo/goml/blob/e1f51f7135988cf33ef5feafa6d1558e4f28d981/linear/linear.go#L236-L273 |
30,402 | cdipaolo/goml | linear/linear.go | J | func (l *LeastSquares) J() (float64, error) {
var sum float64
for i := range l.trainingSet {
prediction, err := l.Predict(l.trainingSet[i])
if err != nil {
return 0, err
}
sum += (l.expectedResults[i] - prediction[0]) * (l.expectedResults[i] - prediction[0])
}
// add regularization term!
//
// notic... | go | func (l *LeastSquares) J() (float64, error) {
var sum float64
for i := range l.trainingSet {
prediction, err := l.Predict(l.trainingSet[i])
if err != nil {
return 0, err
}
sum += (l.expectedResults[i] - prediction[0]) * (l.expectedResults[i] - prediction[0])
}
// add regularization term!
//
// notic... | [
"func",
"(",
"l",
"*",
"LeastSquares",
")",
"J",
"(",
")",
"(",
"float64",
",",
"error",
")",
"{",
"var",
"sum",
"float64",
"\n\n",
"for",
"i",
":=",
"range",
"l",
".",
"trainingSet",
"{",
"prediction",
",",
"err",
":=",
"l",
".",
"Predict",
"(",
... | // J returns the Least Squares cost function of the given linear
// model. Could be useful in testing convergence | [
"J",
"returns",
"the",
"Least",
"Squares",
"cost",
"function",
"of",
"the",
"given",
"linear",
"model",
".",
"Could",
"be",
"useful",
"in",
"testing",
"convergence"
] | e1f51f7135988cf33ef5feafa6d1558e4f28d981 | https://github.com/cdipaolo/goml/blob/e1f51f7135988cf33ef5feafa6d1558e4f28d981/linear/linear.go#L562-L582 |
30,403 | spacemonkeygo/openssl | http.go | ListenAndServeTLS | func ListenAndServeTLS(addr string, cert_file string, key_file string,
handler http.Handler) error {
return ServerListenAndServeTLS(
&http.Server{Addr: addr, Handler: handler}, cert_file, key_file)
} | go | func ListenAndServeTLS(addr string, cert_file string, key_file string,
handler http.Handler) error {
return ServerListenAndServeTLS(
&http.Server{Addr: addr, Handler: handler}, cert_file, key_file)
} | [
"func",
"ListenAndServeTLS",
"(",
"addr",
"string",
",",
"cert_file",
"string",
",",
"key_file",
"string",
",",
"handler",
"http",
".",
"Handler",
")",
"error",
"{",
"return",
"ServerListenAndServeTLS",
"(",
"&",
"http",
".",
"Server",
"{",
"Addr",
":",
"add... | // ListenAndServeTLS will take an http.Handler and serve it using OpenSSL over
// the given tcp address, configured to use the provided cert and key files. | [
"ListenAndServeTLS",
"will",
"take",
"an",
"http",
".",
"Handler",
"and",
"serve",
"it",
"using",
"OpenSSL",
"over",
"the",
"given",
"tcp",
"address",
"configured",
"to",
"use",
"the",
"provided",
"cert",
"and",
"key",
"files",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/http.go#L23-L27 |
30,404 | spacemonkeygo/openssl | http.go | ServerListenAndServeTLS | func ServerListenAndServeTLS(srv *http.Server,
cert_file, key_file string) error {
addr := srv.Addr
if addr == "" {
addr = ":https"
}
ctx, err := NewCtxFromFiles(cert_file, key_file)
if err != nil {
return err
}
l, err := Listen("tcp", addr, ctx)
if err != nil {
return err
}
return srv.Serve(l)
} | go | func ServerListenAndServeTLS(srv *http.Server,
cert_file, key_file string) error {
addr := srv.Addr
if addr == "" {
addr = ":https"
}
ctx, err := NewCtxFromFiles(cert_file, key_file)
if err != nil {
return err
}
l, err := Listen("tcp", addr, ctx)
if err != nil {
return err
}
return srv.Serve(l)
} | [
"func",
"ServerListenAndServeTLS",
"(",
"srv",
"*",
"http",
".",
"Server",
",",
"cert_file",
",",
"key_file",
"string",
")",
"error",
"{",
"addr",
":=",
"srv",
".",
"Addr",
"\n",
"if",
"addr",
"==",
"\"",
"\"",
"{",
"addr",
"=",
"\"",
"\"",
"\n",
"}"... | // ServerListenAndServeTLS will take an http.Server and serve it using OpenSSL
// configured to use the provided cert and key files. | [
"ServerListenAndServeTLS",
"will",
"take",
"an",
"http",
".",
"Server",
"and",
"serve",
"it",
"using",
"OpenSSL",
"configured",
"to",
"use",
"the",
"provided",
"cert",
"and",
"key",
"files",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/http.go#L31-L49 |
30,405 | spacemonkeygo/openssl | init.go | errorFromErrorQueue | func errorFromErrorQueue() error {
var errs []string
for {
err := C.ERR_get_error()
if err == 0 {
break
}
errs = append(errs, fmt.Sprintf("%s:%s:%s",
C.GoString(C.ERR_lib_error_string(err)),
C.GoString(C.ERR_func_error_string(err)),
C.GoString(C.ERR_reason_error_string(err))))
}
return errors.Ne... | go | func errorFromErrorQueue() error {
var errs []string
for {
err := C.ERR_get_error()
if err == 0 {
break
}
errs = append(errs, fmt.Sprintf("%s:%s:%s",
C.GoString(C.ERR_lib_error_string(err)),
C.GoString(C.ERR_func_error_string(err)),
C.GoString(C.ERR_reason_error_string(err))))
}
return errors.Ne... | [
"func",
"errorFromErrorQueue",
"(",
")",
"error",
"{",
"var",
"errs",
"[",
"]",
"string",
"\n",
"for",
"{",
"err",
":=",
"C",
".",
"ERR_get_error",
"(",
")",
"\n",
"if",
"err",
"==",
"0",
"{",
"break",
"\n",
"}",
"\n",
"errs",
"=",
"append",
"(",
... | // errorFromErrorQueue needs to run in the same OS thread as the operation
// that caused the possible error | [
"errorFromErrorQueue",
"needs",
"to",
"run",
"in",
"the",
"same",
"OS",
"thread",
"as",
"the",
"operation",
"that",
"caused",
"the",
"possible",
"error"
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/init.go#L104-L117 |
30,406 | spacemonkeygo/openssl | cert.go | NewName | func NewName() (*Name, error) {
n := C.X509_NAME_new()
if n == nil {
return nil, errors.New("could not create x509 name")
}
name := &Name{name: n}
runtime.SetFinalizer(name, func(n *Name) {
C.X509_NAME_free(n.name)
})
return name, nil
} | go | func NewName() (*Name, error) {
n := C.X509_NAME_new()
if n == nil {
return nil, errors.New("could not create x509 name")
}
name := &Name{name: n}
runtime.SetFinalizer(name, func(n *Name) {
C.X509_NAME_free(n.name)
})
return name, nil
} | [
"func",
"NewName",
"(",
")",
"(",
"*",
"Name",
",",
"error",
")",
"{",
"n",
":=",
"C",
".",
"X509_NAME_new",
"(",
")",
"\n",
"if",
"n",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"name... | // Allocate and return a new Name object. | [
"Allocate",
"and",
"return",
"a",
"new",
"Name",
"object",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/cert.go#L78-L88 |
30,407 | spacemonkeygo/openssl | cert.go | AddTextEntry | func (n *Name) AddTextEntry(field, value string) error {
cfield := C.CString(field)
defer C.free(unsafe.Pointer(cfield))
cvalue := (*C.uchar)(unsafe.Pointer(C.CString(value)))
defer C.free(unsafe.Pointer(cvalue))
ret := C.X509_NAME_add_entry_by_txt(
n.name, cfield, C.MBSTRING_ASC, cvalue, -1, -1, 0)
if ret != 1... | go | func (n *Name) AddTextEntry(field, value string) error {
cfield := C.CString(field)
defer C.free(unsafe.Pointer(cfield))
cvalue := (*C.uchar)(unsafe.Pointer(C.CString(value)))
defer C.free(unsafe.Pointer(cvalue))
ret := C.X509_NAME_add_entry_by_txt(
n.name, cfield, C.MBSTRING_ASC, cvalue, -1, -1, 0)
if ret != 1... | [
"func",
"(",
"n",
"*",
"Name",
")",
"AddTextEntry",
"(",
"field",
",",
"value",
"string",
")",
"error",
"{",
"cfield",
":=",
"C",
".",
"CString",
"(",
"field",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"cfield",
")",... | // AddTextEntry appends a text entry to an X509 NAME. | [
"AddTextEntry",
"appends",
"a",
"text",
"entry",
"to",
"an",
"X509",
"NAME",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/cert.go#L91-L102 |
30,408 | spacemonkeygo/openssl | cert.go | AddTextEntries | func (n *Name) AddTextEntries(entries map[string]string) error {
for f, v := range entries {
if err := n.AddTextEntry(f, v); err != nil {
return err
}
}
return nil
} | go | func (n *Name) AddTextEntries(entries map[string]string) error {
for f, v := range entries {
if err := n.AddTextEntry(f, v); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"n",
"*",
"Name",
")",
"AddTextEntries",
"(",
"entries",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"for",
"f",
",",
"v",
":=",
"range",
"entries",
"{",
"if",
"err",
":=",
"n",
".",
"AddTextEntry",
"(",
"f",
",",
"v",
")... | // AddTextEntries allows adding multiple entries to a name in one call. | [
"AddTextEntries",
"allows",
"adding",
"multiple",
"entries",
"to",
"a",
"name",
"in",
"one",
"call",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/cert.go#L105-L112 |
30,409 | spacemonkeygo/openssl | cert.go | NewCertificate | func NewCertificate(info *CertificateInfo, key PublicKey) (*Certificate, error) {
c := &Certificate{x: C.X509_new()}
runtime.SetFinalizer(c, func(c *Certificate) {
C.X509_free(c.x)
})
name, err := c.GetSubjectName()
if err != nil {
return nil, err
}
err = name.AddTextEntries(map[string]string{
"C": info.... | go | func NewCertificate(info *CertificateInfo, key PublicKey) (*Certificate, error) {
c := &Certificate{x: C.X509_new()}
runtime.SetFinalizer(c, func(c *Certificate) {
C.X509_free(c.x)
})
name, err := c.GetSubjectName()
if err != nil {
return nil, err
}
err = name.AddTextEntries(map[string]string{
"C": info.... | [
"func",
"NewCertificate",
"(",
"info",
"*",
"CertificateInfo",
",",
"key",
"PublicKey",
")",
"(",
"*",
"Certificate",
",",
"error",
")",
"{",
"c",
":=",
"&",
"Certificate",
"{",
"x",
":",
"C",
".",
"X509_new",
"(",
")",
"}",
"\n",
"runtime",
".",
"Se... | // NewCertificate generates a basic certificate based
// on the provided CertificateInfo struct | [
"NewCertificate",
"generates",
"a",
"basic",
"certificate",
"based",
"on",
"the",
"provided",
"CertificateInfo",
"struct"
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/cert.go#L129-L164 |
30,410 | spacemonkeygo/openssl | cert.go | SetIssuer | func (c *Certificate) SetIssuer(issuer *Certificate) error {
name, err := issuer.GetSubjectName()
if err != nil {
return err
}
if err = c.SetIssuerName(name); err != nil {
return err
}
c.Issuer = issuer
return nil
} | go | func (c *Certificate) SetIssuer(issuer *Certificate) error {
name, err := issuer.GetSubjectName()
if err != nil {
return err
}
if err = c.SetIssuerName(name); err != nil {
return err
}
c.Issuer = issuer
return nil
} | [
"func",
"(",
"c",
"*",
"Certificate",
")",
"SetIssuer",
"(",
"issuer",
"*",
"Certificate",
")",
"error",
"{",
"name",
",",
"err",
":=",
"issuer",
".",
"GetSubjectName",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
... | // SetIssuer updates the stored Issuer cert
// and the internal x509 Issuer Name of a certificate.
// The stored Issuer reference is used when adding extensions. | [
"SetIssuer",
"updates",
"the",
"stored",
"Issuer",
"cert",
"and",
"the",
"internal",
"x509",
"Issuer",
"Name",
"of",
"a",
"certificate",
".",
"The",
"stored",
"Issuer",
"reference",
"is",
"used",
"when",
"adding",
"extensions",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/cert.go#L192-L202 |
30,411 | spacemonkeygo/openssl | cert.go | SetIssuerName | func (c *Certificate) SetIssuerName(name *Name) error {
if C.X509_set_issuer_name(c.x, name.name) != 1 {
return errors.New("failed to set subject name")
}
return nil
} | go | func (c *Certificate) SetIssuerName(name *Name) error {
if C.X509_set_issuer_name(c.x, name.name) != 1 {
return errors.New("failed to set subject name")
}
return nil
} | [
"func",
"(",
"c",
"*",
"Certificate",
")",
"SetIssuerName",
"(",
"name",
"*",
"Name",
")",
"error",
"{",
"if",
"C",
".",
"X509_set_issuer_name",
"(",
"c",
".",
"x",
",",
"name",
".",
"name",
")",
"!=",
"1",
"{",
"return",
"errors",
".",
"New",
"(",... | // SetIssuerName populates the issuer name of a certificate.
// Use SetIssuer instead, if possible. | [
"SetIssuerName",
"populates",
"the",
"issuer",
"name",
"of",
"a",
"certificate",
".",
"Use",
"SetIssuer",
"instead",
"if",
"possible",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/cert.go#L206-L211 |
30,412 | spacemonkeygo/openssl | cert.go | SetSerial | func (c *Certificate) SetSerial(serial *big.Int) error {
sno := C.ASN1_INTEGER_new()
defer C.ASN1_INTEGER_free(sno)
bn := C.BN_new()
defer C.BN_free(bn)
serialBytes := serial.Bytes()
if bn = C.BN_bin2bn((*C.uchar)(unsafe.Pointer(&serialBytes[0])), C.int(len(serialBytes)), bn); bn == nil {
return errors.New("fa... | go | func (c *Certificate) SetSerial(serial *big.Int) error {
sno := C.ASN1_INTEGER_new()
defer C.ASN1_INTEGER_free(sno)
bn := C.BN_new()
defer C.BN_free(bn)
serialBytes := serial.Bytes()
if bn = C.BN_bin2bn((*C.uchar)(unsafe.Pointer(&serialBytes[0])), C.int(len(serialBytes)), bn); bn == nil {
return errors.New("fa... | [
"func",
"(",
"c",
"*",
"Certificate",
")",
"SetSerial",
"(",
"serial",
"*",
"big",
".",
"Int",
")",
"error",
"{",
"sno",
":=",
"C",
".",
"ASN1_INTEGER_new",
"(",
")",
"\n",
"defer",
"C",
".",
"ASN1_INTEGER_free",
"(",
"sno",
")",
"\n",
"bn",
":=",
... | // SetSerial sets the serial of a certificate. | [
"SetSerial",
"sets",
"the",
"serial",
"of",
"a",
"certificate",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/cert.go#L214-L231 |
30,413 | spacemonkeygo/openssl | cert.go | SetExpireDate | func (c *Certificate) SetExpireDate(when time.Duration) error {
offset := C.long(when / time.Second)
result := C.X509_gmtime_adj(C.X_X509_get0_notAfter(c.x), offset)
if result == nil {
return errors.New("failed to set expire date")
}
return nil
} | go | func (c *Certificate) SetExpireDate(when time.Duration) error {
offset := C.long(when / time.Second)
result := C.X509_gmtime_adj(C.X_X509_get0_notAfter(c.x), offset)
if result == nil {
return errors.New("failed to set expire date")
}
return nil
} | [
"func",
"(",
"c",
"*",
"Certificate",
")",
"SetExpireDate",
"(",
"when",
"time",
".",
"Duration",
")",
"error",
"{",
"offset",
":=",
"C",
".",
"long",
"(",
"when",
"/",
"time",
".",
"Second",
")",
"\n",
"result",
":=",
"C",
".",
"X509_gmtime_adj",
"(... | // SetExpireDate sets the certificate issue date relative to the current time. | [
"SetExpireDate",
"sets",
"the",
"certificate",
"issue",
"date",
"relative",
"to",
"the",
"current",
"time",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/cert.go#L244-L251 |
30,414 | spacemonkeygo/openssl | cert.go | SetPubKey | func (c *Certificate) SetPubKey(pubKey PublicKey) error {
c.pubKey = pubKey
if C.X509_set_pubkey(c.x, pubKey.evpPKey()) != 1 {
return errors.New("failed to set public key")
}
return nil
} | go | func (c *Certificate) SetPubKey(pubKey PublicKey) error {
c.pubKey = pubKey
if C.X509_set_pubkey(c.x, pubKey.evpPKey()) != 1 {
return errors.New("failed to set public key")
}
return nil
} | [
"func",
"(",
"c",
"*",
"Certificate",
")",
"SetPubKey",
"(",
"pubKey",
"PublicKey",
")",
"error",
"{",
"c",
".",
"pubKey",
"=",
"pubKey",
"\n",
"if",
"C",
".",
"X509_set_pubkey",
"(",
"c",
".",
"x",
",",
"pubKey",
".",
"evpPKey",
"(",
")",
")",
"!=... | // SetPubKey assigns a new public key to a certificate. | [
"SetPubKey",
"assigns",
"a",
"new",
"public",
"key",
"to",
"a",
"certificate",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/cert.go#L254-L260 |
30,415 | spacemonkeygo/openssl | cert.go | Sign | func (c *Certificate) Sign(privKey PrivateKey, digest EVP_MD) error {
switch digest {
case EVP_SHA256:
case EVP_SHA384:
case EVP_SHA512:
default:
return errors.New("Unsupported digest" +
"You're probably looking for 'EVP_SHA256' or 'EVP_SHA512'.")
}
return c.insecureSign(privKey, digest)
} | go | func (c *Certificate) Sign(privKey PrivateKey, digest EVP_MD) error {
switch digest {
case EVP_SHA256:
case EVP_SHA384:
case EVP_SHA512:
default:
return errors.New("Unsupported digest" +
"You're probably looking for 'EVP_SHA256' or 'EVP_SHA512'.")
}
return c.insecureSign(privKey, digest)
} | [
"func",
"(",
"c",
"*",
"Certificate",
")",
"Sign",
"(",
"privKey",
"PrivateKey",
",",
"digest",
"EVP_MD",
")",
"error",
"{",
"switch",
"digest",
"{",
"case",
"EVP_SHA256",
":",
"case",
"EVP_SHA384",
":",
"case",
"EVP_SHA512",
":",
"default",
":",
"return",... | // Sign a certificate using a private key and a digest name.
// Accepted digest names are 'sha256', 'sha384', and 'sha512'. | [
"Sign",
"a",
"certificate",
"using",
"a",
"private",
"key",
"and",
"a",
"digest",
"name",
".",
"Accepted",
"digest",
"names",
"are",
"sha256",
"sha384",
"and",
"sha512",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/cert.go#L264-L274 |
30,416 | spacemonkeygo/openssl | cert.go | AddExtensions | func (c *Certificate) AddExtensions(extensions map[NID]string) error {
for nid, value := range extensions {
if err := c.AddExtension(nid, value); err != nil {
return err
}
}
return nil
} | go | func (c *Certificate) AddExtensions(extensions map[NID]string) error {
for nid, value := range extensions {
if err := c.AddExtension(nid, value); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"c",
"*",
"Certificate",
")",
"AddExtensions",
"(",
"extensions",
"map",
"[",
"NID",
"]",
"string",
")",
"error",
"{",
"for",
"nid",
",",
"value",
":=",
"range",
"extensions",
"{",
"if",
"err",
":=",
"c",
".",
"AddExtension",
"(",
"nid",
... | // Wraps AddExtension using a map of NID to text extension.
// Will return without finishing if it encounters an error. | [
"Wraps",
"AddExtension",
"using",
"a",
"map",
"of",
"NID",
"to",
"text",
"extension",
".",
"Will",
"return",
"without",
"finishing",
"if",
"it",
"encounters",
"an",
"error",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/cert.go#L336-L343 |
30,417 | spacemonkeygo/openssl | cert.go | LoadCertificateFromPEM | func LoadCertificateFromPEM(pem_block []byte) (*Certificate, error) {
if len(pem_block) == 0 {
return nil, errors.New("empty pem block")
}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
bio := C.BIO_new_mem_buf(unsafe.Pointer(&pem_block[0]),
C.int(len(pem_block)))
cert := C.PEM_read_bio_X509(bio, nil, ... | go | func LoadCertificateFromPEM(pem_block []byte) (*Certificate, error) {
if len(pem_block) == 0 {
return nil, errors.New("empty pem block")
}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
bio := C.BIO_new_mem_buf(unsafe.Pointer(&pem_block[0]),
C.int(len(pem_block)))
cert := C.PEM_read_bio_X509(bio, nil, ... | [
"func",
"LoadCertificateFromPEM",
"(",
"pem_block",
"[",
"]",
"byte",
")",
"(",
"*",
"Certificate",
",",
"error",
")",
"{",
"if",
"len",
"(",
"pem_block",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
... | // LoadCertificateFromPEM loads an X509 certificate from a PEM-encoded block. | [
"LoadCertificateFromPEM",
"loads",
"an",
"X509",
"certificate",
"from",
"a",
"PEM",
"-",
"encoded",
"block",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/cert.go#L346-L364 |
30,418 | spacemonkeygo/openssl | cert.go | MarshalPEM | func (c *Certificate) MarshalPEM() (pem_block []byte, err error) {
bio := C.BIO_new(C.BIO_s_mem())
if bio == nil {
return nil, errors.New("failed to allocate memory BIO")
}
defer C.BIO_free(bio)
if int(C.PEM_write_bio_X509(bio, c.x)) != 1 {
return nil, errors.New("failed dumping certificate")
}
return ioutil... | go | func (c *Certificate) MarshalPEM() (pem_block []byte, err error) {
bio := C.BIO_new(C.BIO_s_mem())
if bio == nil {
return nil, errors.New("failed to allocate memory BIO")
}
defer C.BIO_free(bio)
if int(C.PEM_write_bio_X509(bio, c.x)) != 1 {
return nil, errors.New("failed dumping certificate")
}
return ioutil... | [
"func",
"(",
"c",
"*",
"Certificate",
")",
"MarshalPEM",
"(",
")",
"(",
"pem_block",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"bio",
":=",
"C",
".",
"BIO_new",
"(",
"C",
".",
"BIO_s_mem",
"(",
")",
")",
"\n",
"if",
"bio",
"==",
"nil",
"... | // MarshalPEM converts the X509 certificate to PEM-encoded format | [
"MarshalPEM",
"converts",
"the",
"X509",
"certificate",
"to",
"PEM",
"-",
"encoded",
"format"
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/cert.go#L367-L377 |
30,419 | spacemonkeygo/openssl | cert.go | PublicKey | func (c *Certificate) PublicKey() (PublicKey, error) {
pkey := C.X509_get_pubkey(c.x)
if pkey == nil {
return nil, errors.New("no public key found")
}
key := &pKey{key: pkey}
runtime.SetFinalizer(key, func(key *pKey) {
C.EVP_PKEY_free(key.key)
})
return key, nil
} | go | func (c *Certificate) PublicKey() (PublicKey, error) {
pkey := C.X509_get_pubkey(c.x)
if pkey == nil {
return nil, errors.New("no public key found")
}
key := &pKey{key: pkey}
runtime.SetFinalizer(key, func(key *pKey) {
C.EVP_PKEY_free(key.key)
})
return key, nil
} | [
"func",
"(",
"c",
"*",
"Certificate",
")",
"PublicKey",
"(",
")",
"(",
"PublicKey",
",",
"error",
")",
"{",
"pkey",
":=",
"C",
".",
"X509_get_pubkey",
"(",
"c",
".",
"x",
")",
"\n",
"if",
"pkey",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
... | // PublicKey returns the public key embedded in the X509 certificate. | [
"PublicKey",
"returns",
"the",
"public",
"key",
"embedded",
"in",
"the",
"X509",
"certificate",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/cert.go#L380-L390 |
30,420 | spacemonkeygo/openssl | cert.go | GetSerialNumberHex | func (c *Certificate) GetSerialNumberHex() (serial string) {
asn1_i := C.X509_get_serialNumber(c.x)
bignum := C.ASN1_INTEGER_to_BN(asn1_i, nil)
hex := C.BN_bn2hex(bignum)
serial = C.GoString(hex)
C.BN_free(bignum)
C.X_OPENSSL_free(unsafe.Pointer(hex))
return
} | go | func (c *Certificate) GetSerialNumberHex() (serial string) {
asn1_i := C.X509_get_serialNumber(c.x)
bignum := C.ASN1_INTEGER_to_BN(asn1_i, nil)
hex := C.BN_bn2hex(bignum)
serial = C.GoString(hex)
C.BN_free(bignum)
C.X_OPENSSL_free(unsafe.Pointer(hex))
return
} | [
"func",
"(",
"c",
"*",
"Certificate",
")",
"GetSerialNumberHex",
"(",
")",
"(",
"serial",
"string",
")",
"{",
"asn1_i",
":=",
"C",
".",
"X509_get_serialNumber",
"(",
"c",
".",
"x",
")",
"\n",
"bignum",
":=",
"C",
".",
"ASN1_INTEGER_to_BN",
"(",
"asn1_i",... | // GetSerialNumberHex returns the certificate's serial number in hex format | [
"GetSerialNumberHex",
"returns",
"the",
"certificate",
"s",
"serial",
"number",
"in",
"hex",
"format"
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/cert.go#L393-L401 |
30,421 | spacemonkeygo/openssl | cert.go | SetVersion | func (c *Certificate) SetVersion(version X509_Version) error {
cvers := C.long(version)
if C.X_X509_set_version(c.x, cvers) != 1 {
return errors.New("failed to set certificate version")
}
return nil
} | go | func (c *Certificate) SetVersion(version X509_Version) error {
cvers := C.long(version)
if C.X_X509_set_version(c.x, cvers) != 1 {
return errors.New("failed to set certificate version")
}
return nil
} | [
"func",
"(",
"c",
"*",
"Certificate",
")",
"SetVersion",
"(",
"version",
"X509_Version",
")",
"error",
"{",
"cvers",
":=",
"C",
".",
"long",
"(",
"version",
")",
"\n",
"if",
"C",
".",
"X_X509_set_version",
"(",
"c",
".",
"x",
",",
"cvers",
")",
"!=",... | // SetVersion sets the X509 version of the certificate. | [
"SetVersion",
"sets",
"the",
"X509",
"version",
"of",
"the",
"certificate",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/cert.go#L409-L415 |
30,422 | spacemonkeygo/openssl | conn.go | Server | func Server(conn net.Conn, ctx *Ctx) (*Conn, error) {
c, err := newConn(conn, ctx)
if err != nil {
return nil, err
}
C.SSL_set_accept_state(c.ssl)
return c, nil
} | go | func Server(conn net.Conn, ctx *Ctx) (*Conn, error) {
c, err := newConn(conn, ctx)
if err != nil {
return nil, err
}
C.SSL_set_accept_state(c.ssl)
return c, nil
} | [
"func",
"Server",
"(",
"conn",
"net",
".",
"Conn",
",",
"ctx",
"*",
"Ctx",
")",
"(",
"*",
"Conn",
",",
"error",
")",
"{",
"c",
",",
"err",
":=",
"newConn",
"(",
"conn",
",",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",... | // Server wraps an existing stream connection and puts it in the accept state
// for any subsequent handshakes. | [
"Server",
"wraps",
"an",
"existing",
"stream",
"connection",
"and",
"puts",
"it",
"in",
"the",
"accept",
"state",
"for",
"any",
"subsequent",
"handshakes",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/conn.go#L181-L188 |
30,423 | spacemonkeygo/openssl | conn.go | PeerCertificate | func (c *Conn) PeerCertificate() (*Certificate, error) {
c.mtx.Lock()
defer c.mtx.Unlock()
if c.is_shutdown {
return nil, errors.New("connection closed")
}
x := C.SSL_get_peer_certificate(c.ssl)
if x == nil {
return nil, errors.New("no peer certificate found")
}
cert := &Certificate{x: x}
runtime.SetFinali... | go | func (c *Conn) PeerCertificate() (*Certificate, error) {
c.mtx.Lock()
defer c.mtx.Unlock()
if c.is_shutdown {
return nil, errors.New("connection closed")
}
x := C.SSL_get_peer_certificate(c.ssl)
if x == nil {
return nil, errors.New("no peer certificate found")
}
cert := &Certificate{x: x}
runtime.SetFinali... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"PeerCertificate",
"(",
")",
"(",
"*",
"Certificate",
",",
"error",
")",
"{",
"c",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n",
"if",
"c",
".",
"is_shutdow... | // PeerCertificate returns the Certificate of the peer with which you're
// communicating. Only valid after a handshake. | [
"PeerCertificate",
"returns",
"the",
"Certificate",
"of",
"the",
"peer",
"with",
"which",
"you",
"re",
"communicating",
".",
"Only",
"valid",
"after",
"a",
"handshake",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/conn.go#L316-L331 |
30,424 | spacemonkeygo/openssl | conn.go | loadCertificateStack | func (c *Conn) loadCertificateStack(sk *C.struct_stack_st_X509) (
rv []*Certificate) {
sk_num := int(C.X_sk_X509_num(sk))
rv = make([]*Certificate, 0, sk_num)
for i := 0; i < sk_num; i++ {
x := C.X_sk_X509_value(sk, C.int(i))
// ref holds on to the underlying connection memory so we don't need to
// worry ab... | go | func (c *Conn) loadCertificateStack(sk *C.struct_stack_st_X509) (
rv []*Certificate) {
sk_num := int(C.X_sk_X509_num(sk))
rv = make([]*Certificate, 0, sk_num)
for i := 0; i < sk_num; i++ {
x := C.X_sk_X509_value(sk, C.int(i))
// ref holds on to the underlying connection memory so we don't need to
// worry ab... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"loadCertificateStack",
"(",
"sk",
"*",
"C",
".",
"struct_stack_st_X509",
")",
"(",
"rv",
"[",
"]",
"*",
"Certificate",
")",
"{",
"sk_num",
":=",
"int",
"(",
"C",
".",
"X_sk_X509_num",
"(",
"sk",
")",
")",
"\n",
... | // loadCertificateStack loads up a stack of x509 certificates and returns them,
// handling memory ownership. | [
"loadCertificateStack",
"loads",
"up",
"a",
"stack",
"of",
"x509",
"certificates",
"and",
"returns",
"them",
"handling",
"memory",
"ownership",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/conn.go#L335-L347 |
30,425 | spacemonkeygo/openssl | conn.go | Close | func (c *Conn) Close() error {
c.mtx.Lock()
if c.is_shutdown {
c.mtx.Unlock()
return nil
}
c.is_shutdown = true
c.mtx.Unlock()
var errs utils.ErrorGroup
errs.Add(c.shutdownLoop())
errs.Add(c.conn.Close())
return errs.Finalize()
} | go | func (c *Conn) Close() error {
c.mtx.Lock()
if c.is_shutdown {
c.mtx.Unlock()
return nil
}
c.is_shutdown = true
c.mtx.Unlock()
var errs utils.ErrorGroup
errs.Add(c.shutdownLoop())
errs.Add(c.conn.Close())
return errs.Finalize()
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Close",
"(",
")",
"error",
"{",
"c",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"if",
"c",
".",
"is_shutdown",
"{",
"c",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"c",
".... | // Close shuts down the SSL connection and closes the underlying wrapped
// connection. | [
"Close",
"shuts",
"down",
"the",
"SSL",
"connection",
"and",
"closes",
"the",
"underlying",
"wrapped",
"connection",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/conn.go#L427-L439 |
30,426 | spacemonkeygo/openssl | conn.go | Write | func (c *Conn) Write(b []byte) (written int, err error) {
if len(b) == 0 {
return 0, nil
}
err = tryAgain
for err == tryAgain {
n, errcb := c.write(b)
err = c.handleError(errcb)
if err == nil {
return n, c.flushOutputBuffer()
}
}
return 0, err
} | go | func (c *Conn) Write(b []byte) (written int, err error) {
if len(b) == 0 {
return 0, nil
}
err = tryAgain
for err == tryAgain {
n, errcb := c.write(b)
err = c.handleError(errcb)
if err == nil {
return n, c.flushOutputBuffer()
}
}
return 0, err
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Write",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"written",
"int",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"b",
")",
"==",
"0",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n",
"err",
"=",
"tryAgai... | // Write will encrypt the contents of b and write it to the underlying stream.
// Performance will be vastly improved if the size of b is a multiple of
// SSLRecordSize. | [
"Write",
"will",
"encrypt",
"the",
"contents",
"of",
"b",
"and",
"write",
"it",
"to",
"the",
"underlying",
"stream",
".",
"Performance",
"will",
"be",
"vastly",
"improved",
"if",
"the",
"size",
"of",
"b",
"is",
"a",
"multiple",
"of",
"SSLRecordSize",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/conn.go#L503-L516 |
30,427 | spacemonkeygo/openssl | conn.go | VerifyHostname | func (c *Conn) VerifyHostname(host string) error {
cert, err := c.PeerCertificate()
if err != nil {
return err
}
return cert.VerifyHostname(host)
} | go | func (c *Conn) VerifyHostname(host string) error {
cert, err := c.PeerCertificate()
if err != nil {
return err
}
return cert.VerifyHostname(host)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"VerifyHostname",
"(",
"host",
"string",
")",
"error",
"{",
"cert",
",",
"err",
":=",
"c",
".",
"PeerCertificate",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"cert"... | // VerifyHostname pulls the PeerCertificate and calls VerifyHostname on the
// certificate. | [
"VerifyHostname",
"pulls",
"the",
"PeerCertificate",
"and",
"calls",
"VerifyHostname",
"on",
"the",
"certificate",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/conn.go#L520-L526 |
30,428 | spacemonkeygo/openssl | digest.go | GetDigestByName | func GetDigestByName(name string) (*Digest, error) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
p := C.X_EVP_get_digestbyname(cname)
if p == nil {
return nil, fmt.Errorf("Digest %v not found", name)
}
// we can consider digests to use static mem; don't need to free
return &Digest{ptr: p}, nil... | go | func GetDigestByName(name string) (*Digest, error) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
p := C.X_EVP_get_digestbyname(cname)
if p == nil {
return nil, fmt.Errorf("Digest %v not found", name)
}
// we can consider digests to use static mem; don't need to free
return &Digest{ptr: p}, nil... | [
"func",
"GetDigestByName",
"(",
"name",
"string",
")",
"(",
"*",
"Digest",
",",
"error",
")",
"{",
"cname",
":=",
"C",
".",
"CString",
"(",
"name",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"cname",
")",
")",
"\n",
... | // GetDigestByName returns the Digest with the name or nil and an error if the
// digest was not found. | [
"GetDigestByName",
"returns",
"the",
"Digest",
"with",
"the",
"name",
"or",
"nil",
"and",
"an",
"error",
"if",
"the",
"digest",
"was",
"not",
"found",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/digest.go#L32-L41 |
30,429 | spacemonkeygo/openssl | digest.go | GetDigestByNid | func GetDigestByNid(nid NID) (*Digest, error) {
sn, err := Nid2ShortName(nid)
if err != nil {
return nil, err
}
return GetDigestByName(sn)
} | go | func GetDigestByNid(nid NID) (*Digest, error) {
sn, err := Nid2ShortName(nid)
if err != nil {
return nil, err
}
return GetDigestByName(sn)
} | [
"func",
"GetDigestByNid",
"(",
"nid",
"NID",
")",
"(",
"*",
"Digest",
",",
"error",
")",
"{",
"sn",
",",
"err",
":=",
"Nid2ShortName",
"(",
"nid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"... | // GetDigestByName returns the Digest with the NID or nil and an error if the
// digest was not found. | [
"GetDigestByName",
"returns",
"the",
"Digest",
"with",
"the",
"NID",
"or",
"nil",
"and",
"an",
"error",
"if",
"the",
"digest",
"was",
"not",
"found",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/digest.go#L45-L51 |
30,430 | spacemonkeygo/openssl | utils/errors.go | Add | func (e *ErrorGroup) Add(err error) {
if err != nil {
e.Errors = append(e.Errors, err)
}
} | go | func (e *ErrorGroup) Add(err error) {
if err != nil {
e.Errors = append(e.Errors, err)
}
} | [
"func",
"(",
"e",
"*",
"ErrorGroup",
")",
"Add",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"e",
".",
"Errors",
"=",
"append",
"(",
"e",
".",
"Errors",
",",
"err",
")",
"\n",
"}",
"\n",
"}"
] | // Add adds an error to an existing error group | [
"Add",
"adds",
"an",
"error",
"to",
"an",
"existing",
"error",
"group"
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/utils/errors.go#L28-L32 |
30,431 | spacemonkeygo/openssl | utils/errors.go | Finalize | func (e *ErrorGroup) Finalize() error {
if len(e.Errors) == 0 {
return nil
}
if len(e.Errors) == 1 {
return e.Errors[0]
}
msgs := make([]string, 0, len(e.Errors))
for _, err := range e.Errors {
msgs = append(msgs, err.Error())
}
return errors.New(strings.Join(msgs, "\n"))
} | go | func (e *ErrorGroup) Finalize() error {
if len(e.Errors) == 0 {
return nil
}
if len(e.Errors) == 1 {
return e.Errors[0]
}
msgs := make([]string, 0, len(e.Errors))
for _, err := range e.Errors {
msgs = append(msgs, err.Error())
}
return errors.New(strings.Join(msgs, "\n"))
} | [
"func",
"(",
"e",
"*",
"ErrorGroup",
")",
"Finalize",
"(",
")",
"error",
"{",
"if",
"len",
"(",
"e",
".",
"Errors",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"len",
"(",
"e",
".",
"Errors",
")",
"==",
"1",
"{",
"return",
"e... | // Finalize returns an error corresponding to the ErrorGroup state. If there's
// no errors in the group, finalize returns nil. If there's only one error,
// Finalize returns that error. Otherwise, Finalize will make a new error
// consisting of the messages from the constituent errors. | [
"Finalize",
"returns",
"an",
"error",
"corresponding",
"to",
"the",
"ErrorGroup",
"state",
".",
"If",
"there",
"s",
"no",
"errors",
"in",
"the",
"group",
"finalize",
"returns",
"nil",
".",
"If",
"there",
"s",
"only",
"one",
"error",
"Finalize",
"returns",
... | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/utils/errors.go#L38-L50 |
30,432 | spacemonkeygo/openssl | utils/future.go | NewFuture | func NewFuture() *Future {
mutex := &sync.Mutex{}
return &Future{
mutex: mutex,
cond: sync.NewCond(mutex),
received: false,
val: nil,
err: nil,
}
} | go | func NewFuture() *Future {
mutex := &sync.Mutex{}
return &Future{
mutex: mutex,
cond: sync.NewCond(mutex),
received: false,
val: nil,
err: nil,
}
} | [
"func",
"NewFuture",
"(",
")",
"*",
"Future",
"{",
"mutex",
":=",
"&",
"sync",
".",
"Mutex",
"{",
"}",
"\n",
"return",
"&",
"Future",
"{",
"mutex",
":",
"mutex",
",",
"cond",
":",
"sync",
".",
"NewCond",
"(",
"mutex",
")",
",",
"received",
":",
"... | // NewFuture returns an initialized and ready Future. | [
"NewFuture",
"returns",
"an",
"initialized",
"and",
"ready",
"Future",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/utils/future.go#L36-L45 |
30,433 | spacemonkeygo/openssl | utils/future.go | Get | func (self *Future) Get() (interface{}, error) {
self.mutex.Lock()
defer self.mutex.Unlock()
for {
if self.received {
return self.val, self.err
}
self.cond.Wait()
}
} | go | func (self *Future) Get() (interface{}, error) {
self.mutex.Lock()
defer self.mutex.Unlock()
for {
if self.received {
return self.val, self.err
}
self.cond.Wait()
}
} | [
"func",
"(",
"self",
"*",
"Future",
")",
"Get",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"self",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"self",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"for",
"{",
"if",
"... | // Get blocks until the Future has a value set. | [
"Get",
"blocks",
"until",
"the",
"Future",
"has",
"a",
"value",
"set",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/utils/future.go#L48-L57 |
30,434 | spacemonkeygo/openssl | utils/future.go | Fired | func (self *Future) Fired() bool {
self.mutex.Lock()
defer self.mutex.Unlock()
return self.received
} | go | func (self *Future) Fired() bool {
self.mutex.Lock()
defer self.mutex.Unlock()
return self.received
} | [
"func",
"(",
"self",
"*",
"Future",
")",
"Fired",
"(",
")",
"bool",
"{",
"self",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"self",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"self",
".",
"received",
"\n",
"}"
] | // Fired returns whether or not a value has been set. If Fired is true, Get
// won't block. | [
"Fired",
"returns",
"whether",
"or",
"not",
"a",
"value",
"has",
"been",
"set",
".",
"If",
"Fired",
"is",
"true",
"Get",
"won",
"t",
"block",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/utils/future.go#L61-L65 |
30,435 | spacemonkeygo/openssl | utils/future.go | Set | func (self *Future) Set(val interface{}, err error) {
self.mutex.Lock()
defer self.mutex.Unlock()
if self.received {
return
}
self.received = true
self.val = val
self.err = err
self.cond.Broadcast()
} | go | func (self *Future) Set(val interface{}, err error) {
self.mutex.Lock()
defer self.mutex.Unlock()
if self.received {
return
}
self.received = true
self.val = val
self.err = err
self.cond.Broadcast()
} | [
"func",
"(",
"self",
"*",
"Future",
")",
"Set",
"(",
"val",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"{",
"self",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"self",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"self",
"."... | // Set provides the value to present and future Get calls. If Set has already
// been called, this is a no-op. | [
"Set",
"provides",
"the",
"value",
"to",
"present",
"and",
"future",
"Get",
"calls",
".",
"If",
"Set",
"has",
"already",
"been",
"called",
"this",
"is",
"a",
"no",
"-",
"op",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/utils/future.go#L69-L79 |
30,436 | spacemonkeygo/openssl | key.go | LoadPrivateKeyFromPEM | func LoadPrivateKeyFromPEM(pem_block []byte) (PrivateKey, error) {
if len(pem_block) == 0 {
return nil, errors.New("empty pem block")
}
bio := C.BIO_new_mem_buf(unsafe.Pointer(&pem_block[0]),
C.int(len(pem_block)))
if bio == nil {
return nil, errors.New("failed creating bio")
}
defer C.BIO_free(bio)
key :... | go | func LoadPrivateKeyFromPEM(pem_block []byte) (PrivateKey, error) {
if len(pem_block) == 0 {
return nil, errors.New("empty pem block")
}
bio := C.BIO_new_mem_buf(unsafe.Pointer(&pem_block[0]),
C.int(len(pem_block)))
if bio == nil {
return nil, errors.New("failed creating bio")
}
defer C.BIO_free(bio)
key :... | [
"func",
"LoadPrivateKeyFromPEM",
"(",
"pem_block",
"[",
"]",
"byte",
")",
"(",
"PrivateKey",
",",
"error",
")",
"{",
"if",
"len",
"(",
"pem_block",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\... | // LoadPrivateKeyFromPEM loads a private key from a PEM-encoded block. | [
"LoadPrivateKeyFromPEM",
"loads",
"a",
"private",
"key",
"from",
"a",
"PEM",
"-",
"encoded",
"block",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/key.go#L276-L297 |
30,437 | spacemonkeygo/openssl | key.go | LoadPrivateKeyFromPEMWithPassword | func LoadPrivateKeyFromPEMWithPassword(pem_block []byte, password string) (
PrivateKey, error) {
if len(pem_block) == 0 {
return nil, errors.New("empty pem block")
}
bio := C.BIO_new_mem_buf(unsafe.Pointer(&pem_block[0]),
C.int(len(pem_block)))
if bio == nil {
return nil, errors.New("failed creating bio")
}... | go | func LoadPrivateKeyFromPEMWithPassword(pem_block []byte, password string) (
PrivateKey, error) {
if len(pem_block) == 0 {
return nil, errors.New("empty pem block")
}
bio := C.BIO_new_mem_buf(unsafe.Pointer(&pem_block[0]),
C.int(len(pem_block)))
if bio == nil {
return nil, errors.New("failed creating bio")
}... | [
"func",
"LoadPrivateKeyFromPEMWithPassword",
"(",
"pem_block",
"[",
"]",
"byte",
",",
"password",
"string",
")",
"(",
"PrivateKey",
",",
"error",
")",
"{",
"if",
"len",
"(",
"pem_block",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(... | // LoadPrivateKeyFromPEMWithPassword loads a private key from a PEM-encoded block. | [
"LoadPrivateKeyFromPEMWithPassword",
"loads",
"a",
"private",
"key",
"from",
"a",
"PEM",
"-",
"encoded",
"block",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/key.go#L300-L323 |
30,438 | spacemonkeygo/openssl | key.go | LoadPrivateKeyFromDER | func LoadPrivateKeyFromDER(der_block []byte) (PrivateKey, error) {
if len(der_block) == 0 {
return nil, errors.New("empty der block")
}
bio := C.BIO_new_mem_buf(unsafe.Pointer(&der_block[0]),
C.int(len(der_block)))
if bio == nil {
return nil, errors.New("failed creating bio")
}
defer C.BIO_free(bio)
key :... | go | func LoadPrivateKeyFromDER(der_block []byte) (PrivateKey, error) {
if len(der_block) == 0 {
return nil, errors.New("empty der block")
}
bio := C.BIO_new_mem_buf(unsafe.Pointer(&der_block[0]),
C.int(len(der_block)))
if bio == nil {
return nil, errors.New("failed creating bio")
}
defer C.BIO_free(bio)
key :... | [
"func",
"LoadPrivateKeyFromDER",
"(",
"der_block",
"[",
"]",
"byte",
")",
"(",
"PrivateKey",
",",
"error",
")",
"{",
"if",
"len",
"(",
"der_block",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\... | // LoadPrivateKeyFromDER loads a private key from a DER-encoded block. | [
"LoadPrivateKeyFromDER",
"loads",
"a",
"private",
"key",
"from",
"a",
"DER",
"-",
"encoded",
"block",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/key.go#L326-L347 |
30,439 | spacemonkeygo/openssl | key.go | LoadPrivateKeyFromPEMWidthPassword | func LoadPrivateKeyFromPEMWidthPassword(pem_block []byte, password string) (
PrivateKey, error) {
return LoadPrivateKeyFromPEMWithPassword(pem_block, password)
} | go | func LoadPrivateKeyFromPEMWidthPassword(pem_block []byte, password string) (
PrivateKey, error) {
return LoadPrivateKeyFromPEMWithPassword(pem_block, password)
} | [
"func",
"LoadPrivateKeyFromPEMWidthPassword",
"(",
"pem_block",
"[",
"]",
"byte",
",",
"password",
"string",
")",
"(",
"PrivateKey",
",",
"error",
")",
"{",
"return",
"LoadPrivateKeyFromPEMWithPassword",
"(",
"pem_block",
",",
"password",
")",
"\n",
"}"
] | // LoadPrivateKeyFromPEMWidthPassword loads a private key from a PEM-encoded block.
// Backwards-compatible with typo | [
"LoadPrivateKeyFromPEMWidthPassword",
"loads",
"a",
"private",
"key",
"from",
"a",
"PEM",
"-",
"encoded",
"block",
".",
"Backwards",
"-",
"compatible",
"with",
"typo"
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/key.go#L351-L354 |
30,440 | spacemonkeygo/openssl | key.go | LoadPublicKeyFromPEM | func LoadPublicKeyFromPEM(pem_block []byte) (PublicKey, error) {
if len(pem_block) == 0 {
return nil, errors.New("empty pem block")
}
bio := C.BIO_new_mem_buf(unsafe.Pointer(&pem_block[0]),
C.int(len(pem_block)))
if bio == nil {
return nil, errors.New("failed creating bio")
}
defer C.BIO_free(bio)
key := ... | go | func LoadPublicKeyFromPEM(pem_block []byte) (PublicKey, error) {
if len(pem_block) == 0 {
return nil, errors.New("empty pem block")
}
bio := C.BIO_new_mem_buf(unsafe.Pointer(&pem_block[0]),
C.int(len(pem_block)))
if bio == nil {
return nil, errors.New("failed creating bio")
}
defer C.BIO_free(bio)
key := ... | [
"func",
"LoadPublicKeyFromPEM",
"(",
"pem_block",
"[",
"]",
"byte",
")",
"(",
"PublicKey",
",",
"error",
")",
"{",
"if",
"len",
"(",
"pem_block",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n"... | // LoadPublicKeyFromPEM loads a public key from a PEM-encoded block. | [
"LoadPublicKeyFromPEM",
"loads",
"a",
"public",
"key",
"from",
"a",
"PEM",
"-",
"encoded",
"block",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/key.go#L357-L378 |
30,441 | spacemonkeygo/openssl | key.go | LoadPublicKeyFromDER | func LoadPublicKeyFromDER(der_block []byte) (PublicKey, error) {
if len(der_block) == 0 {
return nil, errors.New("empty der block")
}
bio := C.BIO_new_mem_buf(unsafe.Pointer(&der_block[0]),
C.int(len(der_block)))
if bio == nil {
return nil, errors.New("failed creating bio")
}
defer C.BIO_free(bio)
key := ... | go | func LoadPublicKeyFromDER(der_block []byte) (PublicKey, error) {
if len(der_block) == 0 {
return nil, errors.New("empty der block")
}
bio := C.BIO_new_mem_buf(unsafe.Pointer(&der_block[0]),
C.int(len(der_block)))
if bio == nil {
return nil, errors.New("failed creating bio")
}
defer C.BIO_free(bio)
key := ... | [
"func",
"LoadPublicKeyFromDER",
"(",
"der_block",
"[",
"]",
"byte",
")",
"(",
"PublicKey",
",",
"error",
")",
"{",
"if",
"len",
"(",
"der_block",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n"... | // LoadPublicKeyFromDER loads a public key from a DER-encoded block. | [
"LoadPublicKeyFromDER",
"loads",
"a",
"public",
"key",
"from",
"a",
"DER",
"-",
"encoded",
"block",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/key.go#L381-L402 |
30,442 | spacemonkeygo/openssl | key.go | GenerateRSAKeyWithExponent | func GenerateRSAKeyWithExponent(bits int, exponent int) (PrivateKey, error) {
rsa := C.RSA_generate_key(C.int(bits), C.ulong(exponent), nil, nil)
if rsa == nil {
return nil, errors.New("failed to generate RSA key")
}
key := C.X_EVP_PKEY_new()
if key == nil {
return nil, errors.New("failed to allocate EVP_PKEY"... | go | func GenerateRSAKeyWithExponent(bits int, exponent int) (PrivateKey, error) {
rsa := C.RSA_generate_key(C.int(bits), C.ulong(exponent), nil, nil)
if rsa == nil {
return nil, errors.New("failed to generate RSA key")
}
key := C.X_EVP_PKEY_new()
if key == nil {
return nil, errors.New("failed to allocate EVP_PKEY"... | [
"func",
"GenerateRSAKeyWithExponent",
"(",
"bits",
"int",
",",
"exponent",
"int",
")",
"(",
"PrivateKey",
",",
"error",
")",
"{",
"rsa",
":=",
"C",
".",
"RSA_generate_key",
"(",
"C",
".",
"int",
"(",
"bits",
")",
",",
"C",
".",
"ulong",
"(",
"exponent"... | // GenerateRSAKeyWithExponent generates a new RSA private key. | [
"GenerateRSAKeyWithExponent",
"generates",
"a",
"new",
"RSA",
"private",
"key",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/key.go#L410-L428 |
30,443 | spacemonkeygo/openssl | key.go | GenerateECKey | func GenerateECKey(curve EllipticCurve) (PrivateKey, error) {
// Create context for parameter generation
paramCtx := C.EVP_PKEY_CTX_new_id(C.EVP_PKEY_EC, nil)
if paramCtx == nil {
return nil, errors.New("failed creating EC parameter generation context")
}
defer C.EVP_PKEY_CTX_free(paramCtx)
// Intialize the p... | go | func GenerateECKey(curve EllipticCurve) (PrivateKey, error) {
// Create context for parameter generation
paramCtx := C.EVP_PKEY_CTX_new_id(C.EVP_PKEY_EC, nil)
if paramCtx == nil {
return nil, errors.New("failed creating EC parameter generation context")
}
defer C.EVP_PKEY_CTX_free(paramCtx)
// Intialize the p... | [
"func",
"GenerateECKey",
"(",
"curve",
"EllipticCurve",
")",
"(",
"PrivateKey",
",",
"error",
")",
"{",
"// Create context for parameter generation",
"paramCtx",
":=",
"C",
".",
"EVP_PKEY_CTX_new_id",
"(",
"C",
".",
"EVP_PKEY_EC",
",",
"nil",
")",
"\n",
"if",
"p... | // GenerateECKey generates a new elliptic curve private key on the speicified
// curve. | [
"GenerateECKey",
"generates",
"a",
"new",
"elliptic",
"curve",
"private",
"key",
"on",
"the",
"speicified",
"curve",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/key.go#L432-L479 |
30,444 | spacemonkeygo/openssl | key.go | GenerateED25519Key | func GenerateED25519Key() (PrivateKey, error) {
// Key context
keyCtx := C.EVP_PKEY_CTX_new_id(C.X_EVP_PKEY_ED25519, nil)
if keyCtx == nil {
return nil, errors.New("failed creating EC parameter generation context")
}
defer C.EVP_PKEY_CTX_free(keyCtx)
// Generate the key
var privKey *C.EVP_PKEY
if int(C.EVP_P... | go | func GenerateED25519Key() (PrivateKey, error) {
// Key context
keyCtx := C.EVP_PKEY_CTX_new_id(C.X_EVP_PKEY_ED25519, nil)
if keyCtx == nil {
return nil, errors.New("failed creating EC parameter generation context")
}
defer C.EVP_PKEY_CTX_free(keyCtx)
// Generate the key
var privKey *C.EVP_PKEY
if int(C.EVP_P... | [
"func",
"GenerateED25519Key",
"(",
")",
"(",
"PrivateKey",
",",
"error",
")",
"{",
"// Key context",
"keyCtx",
":=",
"C",
".",
"EVP_PKEY_CTX_new_id",
"(",
"C",
".",
"X_EVP_PKEY_ED25519",
",",
"nil",
")",
"\n",
"if",
"keyCtx",
"==",
"nil",
"{",
"return",
"n... | // GenerateED25519Key generates a Ed25519 key | [
"GenerateED25519Key",
"generates",
"a",
"Ed25519",
"key"
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/key.go#L482-L504 |
30,445 | spacemonkeygo/openssl | dhparam.go | LoadDHParametersFromPEM | func LoadDHParametersFromPEM(pem_block []byte) (*DH, error) {
if len(pem_block) == 0 {
return nil, errors.New("empty pem block")
}
bio := C.BIO_new_mem_buf(unsafe.Pointer(&pem_block[0]),
C.int(len(pem_block)))
if bio == nil {
return nil, errors.New("failed creating bio")
}
defer C.BIO_free(bio)
params := ... | go | func LoadDHParametersFromPEM(pem_block []byte) (*DH, error) {
if len(pem_block) == 0 {
return nil, errors.New("empty pem block")
}
bio := C.BIO_new_mem_buf(unsafe.Pointer(&pem_block[0]),
C.int(len(pem_block)))
if bio == nil {
return nil, errors.New("failed creating bio")
}
defer C.BIO_free(bio)
params := ... | [
"func",
"LoadDHParametersFromPEM",
"(",
"pem_block",
"[",
"]",
"byte",
")",
"(",
"*",
"DH",
",",
"error",
")",
"{",
"if",
"len",
"(",
"pem_block",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"... | // LoadDHParametersFromPEM loads the Diffie-Hellman parameters from
// a PEM-encoded block. | [
"LoadDHParametersFromPEM",
"loads",
"the",
"Diffie",
"-",
"Hellman",
"parameters",
"from",
"a",
"PEM",
"-",
"encoded",
"block",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/dhparam.go#L32-L52 |
30,446 | spacemonkeygo/openssl | dh.go | DeriveSharedSecret | func DeriveSharedSecret(private PrivateKey, public PublicKey) ([]byte, error) {
// Create context for the shared secret derivation
dhCtx := C.EVP_PKEY_CTX_new(private.evpPKey(), nil)
if dhCtx == nil {
return nil, errors.New("failed creating shared secret derivation context")
}
defer C.EVP_PKEY_CTX_free(dhCtx)
... | go | func DeriveSharedSecret(private PrivateKey, public PublicKey) ([]byte, error) {
// Create context for the shared secret derivation
dhCtx := C.EVP_PKEY_CTX_new(private.evpPKey(), nil)
if dhCtx == nil {
return nil, errors.New("failed creating shared secret derivation context")
}
defer C.EVP_PKEY_CTX_free(dhCtx)
... | [
"func",
"DeriveSharedSecret",
"(",
"private",
"PrivateKey",
",",
"public",
"PublicKey",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"// Create context for the shared secret derivation",
"dhCtx",
":=",
"C",
".",
"EVP_PKEY_CTX_new",
"(",
"private",
".",
"evp... | // DeriveSharedSecret derives a shared secret using a private key and a peer's
// public key.
// The specific algorithm that is used depends on the types of the
// keys, but it is most commonly a variant of Diffie-Hellman. | [
"DeriveSharedSecret",
"derives",
"a",
"shared",
"secret",
"using",
"a",
"private",
"key",
"and",
"a",
"peer",
"s",
"public",
"key",
".",
"The",
"specific",
"algorithm",
"that",
"is",
"used",
"depends",
"on",
"the",
"types",
"of",
"the",
"keys",
"but",
"it"... | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/dh.go#L28-L66 |
30,447 | spacemonkeygo/openssl | tickets.go | SetTicketStore | func (c *Ctx) SetTicketStore(store *TicketStore) {
c.ticket_store = store
if store == nil {
C.X_SSL_CTX_set_tlsext_ticket_key_cb(c.ctx, nil)
} else {
C.X_SSL_CTX_set_tlsext_ticket_key_cb(c.ctx,
(*[0]byte)(C.X_SSL_CTX_ticket_key_cb))
}
} | go | func (c *Ctx) SetTicketStore(store *TicketStore) {
c.ticket_store = store
if store == nil {
C.X_SSL_CTX_set_tlsext_ticket_key_cb(c.ctx, nil)
} else {
C.X_SSL_CTX_set_tlsext_ticket_key_cb(c.ctx,
(*[0]byte)(C.X_SSL_CTX_ticket_key_cb))
}
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"SetTicketStore",
"(",
"store",
"*",
"TicketStore",
")",
"{",
"c",
".",
"ticket_store",
"=",
"store",
"\n\n",
"if",
"store",
"==",
"nil",
"{",
"C",
".",
"X_SSL_CTX_set_tlsext_ticket_key_cb",
"(",
"c",
".",
"ctx",
",",
... | // SetTicketStore sets the ticket store for the context so that clients can do
// ticket based session resumption. If the store is nil, the | [
"SetTicketStore",
"sets",
"the",
"ticket",
"store",
"for",
"the",
"context",
"so",
"that",
"clients",
"can",
"do",
"ticket",
"based",
"session",
"resumption",
".",
"If",
"the",
"store",
"is",
"nil",
"the"
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/tickets.go#L213-L222 |
30,448 | spacemonkeygo/openssl | net.go | NewListener | func NewListener(inner net.Listener, ctx *Ctx) net.Listener {
return &listener{
Listener: inner,
ctx: ctx}
} | go | func NewListener(inner net.Listener, ctx *Ctx) net.Listener {
return &listener{
Listener: inner,
ctx: ctx}
} | [
"func",
"NewListener",
"(",
"inner",
"net",
".",
"Listener",
",",
"ctx",
"*",
"Ctx",
")",
"net",
".",
"Listener",
"{",
"return",
"&",
"listener",
"{",
"Listener",
":",
"inner",
",",
"ctx",
":",
"ctx",
"}",
"\n",
"}"
] | // NewListener wraps an existing net.Listener such that all accepted
// connections are wrapped as OpenSSL server connections using the provided
// context ctx. | [
"NewListener",
"wraps",
"an",
"existing",
"net",
".",
"Listener",
"such",
"that",
"all",
"accepted",
"connections",
"are",
"wrapped",
"as",
"OpenSSL",
"server",
"connections",
"using",
"the",
"provided",
"context",
"ctx",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/net.go#L43-L47 |
30,449 | spacemonkeygo/openssl | net.go | Listen | func Listen(network, laddr string, ctx *Ctx) (net.Listener, error) {
if ctx == nil {
return nil, errors.New("no ssl context provided")
}
l, err := net.Listen(network, laddr)
if err != nil {
return nil, err
}
return NewListener(l, ctx), nil
} | go | func Listen(network, laddr string, ctx *Ctx) (net.Listener, error) {
if ctx == nil {
return nil, errors.New("no ssl context provided")
}
l, err := net.Listen(network, laddr)
if err != nil {
return nil, err
}
return NewListener(l, ctx), nil
} | [
"func",
"Listen",
"(",
"network",
",",
"laddr",
"string",
",",
"ctx",
"*",
"Ctx",
")",
"(",
"net",
".",
"Listener",
",",
"error",
")",
"{",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"... | // Listen is a wrapper around net.Listen that wraps incoming connections with
// an OpenSSL server connection using the provided context ctx. | [
"Listen",
"is",
"a",
"wrapper",
"around",
"net",
".",
"Listen",
"that",
"wraps",
"incoming",
"connections",
"with",
"an",
"OpenSSL",
"server",
"connection",
"using",
"the",
"provided",
"context",
"ctx",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/net.go#L51-L60 |
30,450 | spacemonkeygo/openssl | hostname.go | VerifyHostname | func (c *Certificate) VerifyHostname(host string) error {
var ip net.IP
if len(host) >= 3 && host[0] == '[' && host[len(host)-1] == ']' {
ip = net.ParseIP(host[1 : len(host)-1])
} else {
ip = net.ParseIP(host)
}
if ip != nil {
return c.CheckIP(ip, 0)
}
return c.CheckHost(host, 0)
} | go | func (c *Certificate) VerifyHostname(host string) error {
var ip net.IP
if len(host) >= 3 && host[0] == '[' && host[len(host)-1] == ']' {
ip = net.ParseIP(host[1 : len(host)-1])
} else {
ip = net.ParseIP(host)
}
if ip != nil {
return c.CheckIP(ip, 0)
}
return c.CheckHost(host, 0)
} | [
"func",
"(",
"c",
"*",
"Certificate",
")",
"VerifyHostname",
"(",
"host",
"string",
")",
"error",
"{",
"var",
"ip",
"net",
".",
"IP",
"\n",
"if",
"len",
"(",
"host",
")",
">=",
"3",
"&&",
"host",
"[",
"0",
"]",
"==",
"'['",
"&&",
"host",
"[",
"... | // VerifyHostname is a combination of CheckHost and CheckIP. If the provided
// hostname looks like an IP address, it will be checked as an IP address,
// otherwise it will be checked as a hostname.
// Specifically returns ValidationError if the Certificate didn't match but
// there was no internal error. | [
"VerifyHostname",
"is",
"a",
"combination",
"of",
"CheckHost",
"and",
"CheckIP",
".",
"If",
"the",
"provided",
"hostname",
"looks",
"like",
"an",
"IP",
"address",
"it",
"will",
"be",
"checked",
"as",
"an",
"IP",
"address",
"otherwise",
"it",
"will",
"be",
... | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/hostname.go#L121-L132 |
30,451 | spacemonkeygo/openssl | ctx.go | NewCtx | func NewCtx() (*Ctx, error) {
c, err := NewCtxWithVersion(AnyVersion)
if err == nil {
c.SetOptions(NoSSLv2 | NoSSLv3)
}
return c, err
} | go | func NewCtx() (*Ctx, error) {
c, err := NewCtxWithVersion(AnyVersion)
if err == nil {
c.SetOptions(NoSSLv2 | NoSSLv3)
}
return c, err
} | [
"func",
"NewCtx",
"(",
")",
"(",
"*",
"Ctx",
",",
"error",
")",
"{",
"c",
",",
"err",
":=",
"NewCtxWithVersion",
"(",
"AnyVersion",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"c",
".",
"SetOptions",
"(",
"NoSSLv2",
"|",
"NoSSLv3",
")",
"\n",
"}",
... | // NewCtx creates a context that supports any TLS version 1.0 and newer. | [
"NewCtx",
"creates",
"a",
"context",
"that",
"supports",
"any",
"TLS",
"version",
"1",
".",
"0",
"and",
"newer",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/ctx.go#L107-L113 |
30,452 | spacemonkeygo/openssl | ctx.go | NewCtxFromFiles | func NewCtxFromFiles(cert_file string, key_file string) (*Ctx, error) {
ctx, err := NewCtx()
if err != nil {
return nil, err
}
cert_bytes, err := ioutil.ReadFile(cert_file)
if err != nil {
return nil, err
}
certs := SplitPEM(cert_bytes)
if len(certs) == 0 {
return nil, fmt.Errorf("No PEM certificate fou... | go | func NewCtxFromFiles(cert_file string, key_file string) (*Ctx, error) {
ctx, err := NewCtx()
if err != nil {
return nil, err
}
cert_bytes, err := ioutil.ReadFile(cert_file)
if err != nil {
return nil, err
}
certs := SplitPEM(cert_bytes)
if len(certs) == 0 {
return nil, fmt.Errorf("No PEM certificate fou... | [
"func",
"NewCtxFromFiles",
"(",
"cert_file",
"string",
",",
"key_file",
"string",
")",
"(",
"*",
"Ctx",
",",
"error",
")",
"{",
"ctx",
",",
"err",
":=",
"NewCtx",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}"... | // NewCtxFromFiles calls NewCtx, loads the provided files, and configures the
// context to use them. | [
"NewCtxFromFiles",
"calls",
"NewCtx",
"loads",
"the",
"provided",
"files",
"and",
"configures",
"the",
"context",
"to",
"use",
"them",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/ctx.go#L117-L170 |
30,453 | spacemonkeygo/openssl | ctx.go | SetEllipticCurve | func (c *Ctx) SetEllipticCurve(curve EllipticCurve) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
k := C.EC_KEY_new_by_curve_name(C.int(curve))
if k == nil {
return errors.New("Unknown curve")
}
defer C.EC_KEY_free(k)
if int(C.X_SSL_CTX_set_tmp_ecdh(c.ctx, k)) != 1 {
return errorFromErrorQu... | go | func (c *Ctx) SetEllipticCurve(curve EllipticCurve) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
k := C.EC_KEY_new_by_curve_name(C.int(curve))
if k == nil {
return errors.New("Unknown curve")
}
defer C.EC_KEY_free(k)
if int(C.X_SSL_CTX_set_tmp_ecdh(c.ctx, k)) != 1 {
return errorFromErrorQu... | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"SetEllipticCurve",
"(",
"curve",
"EllipticCurve",
")",
"error",
"{",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"(",
")",
"\n\n",
"k",
":=",
"C",
".",
"EC_KEY_new_by_curve_... | // SetEllipticCurve sets the elliptic curve used by the SSL context to
// enable an ECDH cipher suite to be selected during the handshake. | [
"SetEllipticCurve",
"sets",
"the",
"elliptic",
"curve",
"used",
"by",
"the",
"SSL",
"context",
"to",
"enable",
"an",
"ECDH",
"cipher",
"suite",
"to",
"be",
"selected",
"during",
"the",
"handshake",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/ctx.go#L187-L202 |
30,454 | spacemonkeygo/openssl | ctx.go | UseCertificate | func (c *Ctx) UseCertificate(cert *Certificate) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
c.cert = cert
if int(C.SSL_CTX_use_certificate(c.ctx, cert.x)) != 1 {
return errorFromErrorQueue()
}
return nil
} | go | func (c *Ctx) UseCertificate(cert *Certificate) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
c.cert = cert
if int(C.SSL_CTX_use_certificate(c.ctx, cert.x)) != 1 {
return errorFromErrorQueue()
}
return nil
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"UseCertificate",
"(",
"cert",
"*",
"Certificate",
")",
"error",
"{",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"(",
")",
"\n",
"c",
".",
"cert",
"=",
"cert",
"\n",
"... | // UseCertificate configures the context to present the given certificate to
// peers. | [
"UseCertificate",
"configures",
"the",
"context",
"to",
"present",
"the",
"given",
"certificate",
"to",
"peers",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/ctx.go#L206-L214 |
30,455 | spacemonkeygo/openssl | ctx.go | AddChainCertificate | func (c *Ctx) AddChainCertificate(cert *Certificate) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
c.chain = append(c.chain, cert)
if int(C.X_SSL_CTX_add_extra_chain_cert(c.ctx, cert.x)) != 1 {
return errorFromErrorQueue()
}
// OpenSSL takes ownership via SSL_CTX_add_extra_chain_cert
runtime.Se... | go | func (c *Ctx) AddChainCertificate(cert *Certificate) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
c.chain = append(c.chain, cert)
if int(C.X_SSL_CTX_add_extra_chain_cert(c.ctx, cert.x)) != 1 {
return errorFromErrorQueue()
}
// OpenSSL takes ownership via SSL_CTX_add_extra_chain_cert
runtime.Se... | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"AddChainCertificate",
"(",
"cert",
"*",
"Certificate",
")",
"error",
"{",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"(",
")",
"\n",
"c",
".",
"chain",
"=",
"append",
"... | // AddChainCertificate adds a certificate to the chain presented in the
// handshake. | [
"AddChainCertificate",
"adds",
"a",
"certificate",
"to",
"the",
"chain",
"presented",
"in",
"the",
"handshake",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/ctx.go#L218-L228 |
30,456 | spacemonkeygo/openssl | ctx.go | UsePrivateKey | func (c *Ctx) UsePrivateKey(key PrivateKey) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
c.key = key
if int(C.SSL_CTX_use_PrivateKey(c.ctx, key.evpPKey())) != 1 {
return errorFromErrorQueue()
}
return nil
} | go | func (c *Ctx) UsePrivateKey(key PrivateKey) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
c.key = key
if int(C.SSL_CTX_use_PrivateKey(c.ctx, key.evpPKey())) != 1 {
return errorFromErrorQueue()
}
return nil
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"UsePrivateKey",
"(",
"key",
"PrivateKey",
")",
"error",
"{",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"(",
")",
"\n",
"c",
".",
"key",
"=",
"key",
"\n",
"if",
"int"... | // UsePrivateKey configures the context to use the given private key for SSL
// handshakes. | [
"UsePrivateKey",
"configures",
"the",
"context",
"to",
"use",
"the",
"given",
"private",
"key",
"for",
"SSL",
"handshakes",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/ctx.go#L232-L240 |
30,457 | spacemonkeygo/openssl | ctx.go | NewCertificateStore | func NewCertificateStore() (*CertificateStore, error) {
s := C.X509_STORE_new()
if s == nil {
return nil, errors.New("failed to allocate X509_STORE")
}
store := &CertificateStore{store: s}
runtime.SetFinalizer(store, func(s *CertificateStore) {
C.X509_STORE_free(s.store)
})
return store, nil
} | go | func NewCertificateStore() (*CertificateStore, error) {
s := C.X509_STORE_new()
if s == nil {
return nil, errors.New("failed to allocate X509_STORE")
}
store := &CertificateStore{store: s}
runtime.SetFinalizer(store, func(s *CertificateStore) {
C.X509_STORE_free(s.store)
})
return store, nil
} | [
"func",
"NewCertificateStore",
"(",
")",
"(",
"*",
"CertificateStore",
",",
"error",
")",
"{",
"s",
":=",
"C",
".",
"X509_STORE_new",
"(",
")",
"\n",
"if",
"s",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n... | // Allocate a new, empty CertificateStore | [
"Allocate",
"a",
"new",
"empty",
"CertificateStore"
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/ctx.go#L250-L260 |
30,458 | spacemonkeygo/openssl | ctx.go | LoadCertificatesFromPEM | func (s *CertificateStore) LoadCertificatesFromPEM(data []byte) error {
pems := SplitPEM(data)
for _, pem := range pems {
cert, err := LoadCertificateFromPEM(pem)
if err != nil {
return err
}
err = s.AddCertificate(cert)
if err != nil {
return err
}
}
return nil
} | go | func (s *CertificateStore) LoadCertificatesFromPEM(data []byte) error {
pems := SplitPEM(data)
for _, pem := range pems {
cert, err := LoadCertificateFromPEM(pem)
if err != nil {
return err
}
err = s.AddCertificate(cert)
if err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"CertificateStore",
")",
"LoadCertificatesFromPEM",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"pems",
":=",
"SplitPEM",
"(",
"data",
")",
"\n",
"for",
"_",
",",
"pem",
":=",
"range",
"pems",
"{",
"cert",
",",
"err",
":=... | // Parse a chained PEM file, loading all certificates into the Store. | [
"Parse",
"a",
"chained",
"PEM",
"file",
"loading",
"all",
"certificates",
"into",
"the",
"Store",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/ctx.go#L263-L276 |
30,459 | spacemonkeygo/openssl | ctx.go | GetCertificateStore | func (c *Ctx) GetCertificateStore() *CertificateStore {
// we don't need to dealloc the cert store pointer here, because it points
// to a ctx internal. so we do need to keep the ctx around
return &CertificateStore{
store: C.SSL_CTX_get_cert_store(c.ctx),
ctx: c}
} | go | func (c *Ctx) GetCertificateStore() *CertificateStore {
// we don't need to dealloc the cert store pointer here, because it points
// to a ctx internal. so we do need to keep the ctx around
return &CertificateStore{
store: C.SSL_CTX_get_cert_store(c.ctx),
ctx: c}
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"GetCertificateStore",
"(",
")",
"*",
"CertificateStore",
"{",
"// we don't need to dealloc the cert store pointer here, because it points",
"// to a ctx internal. so we do need to keep the ctx around",
"return",
"&",
"CertificateStore",
"{",
"s... | // GetCertificateStore returns the context's certificate store that will be
// used for peer validation. | [
"GetCertificateStore",
"returns",
"the",
"context",
"s",
"certificate",
"store",
"that",
"will",
"be",
"used",
"for",
"peer",
"validation",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/ctx.go#L280-L286 |
30,460 | spacemonkeygo/openssl | ctx.go | AddCertificate | func (s *CertificateStore) AddCertificate(cert *Certificate) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
s.certs = append(s.certs, cert)
if int(C.X509_STORE_add_cert(s.store, cert.x)) != 1 {
return errorFromErrorQueue()
}
return nil
} | go | func (s *CertificateStore) AddCertificate(cert *Certificate) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
s.certs = append(s.certs, cert)
if int(C.X509_STORE_add_cert(s.store, cert.x)) != 1 {
return errorFromErrorQueue()
}
return nil
} | [
"func",
"(",
"s",
"*",
"CertificateStore",
")",
"AddCertificate",
"(",
"cert",
"*",
"Certificate",
")",
"error",
"{",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"(",
")",
"\n",
"s",
".",
"certs",
"=",
"appe... | // AddCertificate marks the provided Certificate as a trusted certificate in
// the given CertificateStore. | [
"AddCertificate",
"marks",
"the",
"provided",
"Certificate",
"as",
"a",
"trusted",
"certificate",
"in",
"the",
"given",
"CertificateStore",
"."
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/ctx.go#L290-L298 |
30,461 | spacemonkeygo/openssl | ctx.go | GetCurrentCert | func (self *CertificateStoreCtx) GetCurrentCert() *Certificate {
x509 := C.X509_STORE_CTX_get_current_cert(self.ctx)
if x509 == nil {
return nil
}
// add a ref
if 1 != C.X_X509_add_ref(x509) {
return nil
}
cert := &Certificate{
x: x509,
}
runtime.SetFinalizer(cert, func(cert *Certificate) {
C.X509_free... | go | func (self *CertificateStoreCtx) GetCurrentCert() *Certificate {
x509 := C.X509_STORE_CTX_get_current_cert(self.ctx)
if x509 == nil {
return nil
}
// add a ref
if 1 != C.X_X509_add_ref(x509) {
return nil
}
cert := &Certificate{
x: x509,
}
runtime.SetFinalizer(cert, func(cert *Certificate) {
C.X509_free... | [
"func",
"(",
"self",
"*",
"CertificateStoreCtx",
")",
"GetCurrentCert",
"(",
")",
"*",
"Certificate",
"{",
"x509",
":=",
"C",
".",
"X509_STORE_CTX_get_current_cert",
"(",
"self",
".",
"ctx",
")",
"\n",
"if",
"x509",
"==",
"nil",
"{",
"return",
"nil",
"\n",... | // the certicate returned is only valid for the lifetime of the underlying
// X509_STORE_CTX | [
"the",
"certicate",
"returned",
"is",
"only",
"valid",
"for",
"the",
"lifetime",
"of",
"the",
"underlying",
"X509_STORE_CTX"
] | c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730 | https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/ctx.go#L324-L340 |
30,462 | jaytaylor/html2text | html2text.go | NewPrettyTablesOptions | func NewPrettyTablesOptions() *PrettyTablesOptions {
return &PrettyTablesOptions{
AutoFormatHeader: true,
AutoWrapText: true,
ReflowDuringAutoWrap: true,
ColWidth: tablewriter.MAX_ROW_WIDTH,
ColumnSeparator: tablewriter.COLUMN,
RowSeparator: tablewriter.ROW,
CenterSep... | go | func NewPrettyTablesOptions() *PrettyTablesOptions {
return &PrettyTablesOptions{
AutoFormatHeader: true,
AutoWrapText: true,
ReflowDuringAutoWrap: true,
ColWidth: tablewriter.MAX_ROW_WIDTH,
ColumnSeparator: tablewriter.COLUMN,
RowSeparator: tablewriter.ROW,
CenterSep... | [
"func",
"NewPrettyTablesOptions",
"(",
")",
"*",
"PrettyTablesOptions",
"{",
"return",
"&",
"PrettyTablesOptions",
"{",
"AutoFormatHeader",
":",
"true",
",",
"AutoWrapText",
":",
"true",
",",
"ReflowDuringAutoWrap",
":",
"true",
",",
"ColWidth",
":",
"tablewriter",
... | // NewPrettyTablesOptions creates PrettyTablesOptions with default settings | [
"NewPrettyTablesOptions",
"creates",
"PrettyTablesOptions",
"with",
"default",
"settings"
] | 01ec452cbe43774f989516272881441cae40c16b | https://github.com/jaytaylor/html2text/blob/01ec452cbe43774f989516272881441cae40c16b/html2text.go#L44-L63 |
30,463 | jaytaylor/html2text | html2text.go | FromHTMLNode | func FromHTMLNode(doc *html.Node, o ...Options) (string, error) {
var options Options
if len(o) > 0 {
options = o[0]
}
ctx := textifyTraverseContext{
buf: bytes.Buffer{},
options: options,
}
if err := ctx.traverse(doc); err != nil {
return "", err
}
text := strings.TrimSpace(newlineRe.ReplaceAllSt... | go | func FromHTMLNode(doc *html.Node, o ...Options) (string, error) {
var options Options
if len(o) > 0 {
options = o[0]
}
ctx := textifyTraverseContext{
buf: bytes.Buffer{},
options: options,
}
if err := ctx.traverse(doc); err != nil {
return "", err
}
text := strings.TrimSpace(newlineRe.ReplaceAllSt... | [
"func",
"FromHTMLNode",
"(",
"doc",
"*",
"html",
".",
"Node",
",",
"o",
"...",
"Options",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"options",
"Options",
"\n",
"if",
"len",
"(",
"o",
")",
">",
"0",
"{",
"options",
"=",
"o",
"[",
"0",
"... | // FromHTMLNode renders text output from a pre-parsed HTML document. | [
"FromHTMLNode",
"renders",
"text",
"output",
"from",
"a",
"pre",
"-",
"parsed",
"HTML",
"document",
"."
] | 01ec452cbe43774f989516272881441cae40c16b | https://github.com/jaytaylor/html2text/blob/01ec452cbe43774f989516272881441cae40c16b/html2text.go#L66-L84 |
30,464 | jaytaylor/html2text | html2text.go | FromReader | func FromReader(reader io.Reader, options ...Options) (string, error) {
newReader, err := bom.NewReaderWithoutBom(reader)
if err != nil {
return "", err
}
doc, err := html.Parse(newReader)
if err != nil {
return "", err
}
return FromHTMLNode(doc, options...)
} | go | func FromReader(reader io.Reader, options ...Options) (string, error) {
newReader, err := bom.NewReaderWithoutBom(reader)
if err != nil {
return "", err
}
doc, err := html.Parse(newReader)
if err != nil {
return "", err
}
return FromHTMLNode(doc, options...)
} | [
"func",
"FromReader",
"(",
"reader",
"io",
".",
"Reader",
",",
"options",
"...",
"Options",
")",
"(",
"string",
",",
"error",
")",
"{",
"newReader",
",",
"err",
":=",
"bom",
".",
"NewReaderWithoutBom",
"(",
"reader",
")",
"\n",
"if",
"err",
"!=",
"nil"... | // FromReader renders text output after parsing HTML for the specified
// io.Reader. | [
"FromReader",
"renders",
"text",
"output",
"after",
"parsing",
"HTML",
"for",
"the",
"specified",
"io",
".",
"Reader",
"."
] | 01ec452cbe43774f989516272881441cae40c16b | https://github.com/jaytaylor/html2text/blob/01ec452cbe43774f989516272881441cae40c16b/html2text.go#L88-L98 |
30,465 | jaytaylor/html2text | html2text.go | FromString | func FromString(input string, options ...Options) (string, error) {
bs := bom.CleanBom([]byte(input))
text, err := FromReader(bytes.NewReader(bs), options...)
if err != nil {
return "", err
}
return text, nil
} | go | func FromString(input string, options ...Options) (string, error) {
bs := bom.CleanBom([]byte(input))
text, err := FromReader(bytes.NewReader(bs), options...)
if err != nil {
return "", err
}
return text, nil
} | [
"func",
"FromString",
"(",
"input",
"string",
",",
"options",
"...",
"Options",
")",
"(",
"string",
",",
"error",
")",
"{",
"bs",
":=",
"bom",
".",
"CleanBom",
"(",
"[",
"]",
"byte",
"(",
"input",
")",
")",
"\n",
"text",
",",
"err",
":=",
"FromRead... | // FromString parses HTML from the input string, then renders the text form. | [
"FromString",
"parses",
"HTML",
"from",
"the",
"input",
"string",
"then",
"renders",
"the",
"text",
"form",
"."
] | 01ec452cbe43774f989516272881441cae40c16b | https://github.com/jaytaylor/html2text/blob/01ec452cbe43774f989516272881441cae40c16b/html2text.go#L101-L108 |
30,466 | jaytaylor/html2text | html2text.go | paragraphHandler | func (ctx *textifyTraverseContext) paragraphHandler(node *html.Node) error {
if err := ctx.emit("\n\n"); err != nil {
return err
}
if err := ctx.traverseChildren(node); err != nil {
return err
}
return ctx.emit("\n\n")
} | go | func (ctx *textifyTraverseContext) paragraphHandler(node *html.Node) error {
if err := ctx.emit("\n\n"); err != nil {
return err
}
if err := ctx.traverseChildren(node); err != nil {
return err
}
return ctx.emit("\n\n")
} | [
"func",
"(",
"ctx",
"*",
"textifyTraverseContext",
")",
"paragraphHandler",
"(",
"node",
"*",
"html",
".",
"Node",
")",
"error",
"{",
"if",
"err",
":=",
"ctx",
".",
"emit",
"(",
"\"",
"\\n",
"\\n",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
... | // paragraphHandler renders node children surrounded by double newlines. | [
"paragraphHandler",
"renders",
"node",
"children",
"surrounded",
"by",
"double",
"newlines",
"."
] | 01ec452cbe43774f989516272881441cae40c16b | https://github.com/jaytaylor/html2text/blob/01ec452cbe43774f989516272881441cae40c16b/html2text.go#L291-L299 |
30,467 | jaytaylor/html2text | html2text.go | handleTableElement | func (ctx *textifyTraverseContext) handleTableElement(node *html.Node) error {
if !ctx.options.PrettyTables {
panic("handleTableElement invoked when PrettyTables not active")
}
switch node.DataAtom {
case atom.Table:
if err := ctx.emit("\n\n"); err != nil {
return err
}
// Re-intialize all table contex... | go | func (ctx *textifyTraverseContext) handleTableElement(node *html.Node) error {
if !ctx.options.PrettyTables {
panic("handleTableElement invoked when PrettyTables not active")
}
switch node.DataAtom {
case atom.Table:
if err := ctx.emit("\n\n"); err != nil {
return err
}
// Re-intialize all table contex... | [
"func",
"(",
"ctx",
"*",
"textifyTraverseContext",
")",
"handleTableElement",
"(",
"node",
"*",
"html",
".",
"Node",
")",
"error",
"{",
"if",
"!",
"ctx",
".",
"options",
".",
"PrettyTables",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"switc... | // handleTableElement is only to be invoked when options.PrettyTables is active. | [
"handleTableElement",
"is",
"only",
"to",
"be",
"invoked",
"when",
"options",
".",
"PrettyTables",
"is",
"active",
"."
] | 01ec452cbe43774f989516272881441cae40c16b | https://github.com/jaytaylor/html2text/blob/01ec452cbe43774f989516272881441cae40c16b/html2text.go#L302-L390 |
30,468 | jaytaylor/html2text | html2text.go | renderEachChild | func (ctx *textifyTraverseContext) renderEachChild(node *html.Node) (string, error) {
buf := &bytes.Buffer{}
for c := node.FirstChild; c != nil; c = c.NextSibling {
s, err := FromHTMLNode(c, ctx.options)
if err != nil {
return "", err
}
if _, err = buf.WriteString(s); err != nil {
return "", err
}
i... | go | func (ctx *textifyTraverseContext) renderEachChild(node *html.Node) (string, error) {
buf := &bytes.Buffer{}
for c := node.FirstChild; c != nil; c = c.NextSibling {
s, err := FromHTMLNode(c, ctx.options)
if err != nil {
return "", err
}
if _, err = buf.WriteString(s); err != nil {
return "", err
}
i... | [
"func",
"(",
"ctx",
"*",
"textifyTraverseContext",
")",
"renderEachChild",
"(",
"node",
"*",
"html",
".",
"Node",
")",
"(",
"string",
",",
"error",
")",
"{",
"buf",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"for",
"c",
":=",
"node",
".",
"... | // renderEachChild visits each direct child of a node and collects the sequence of
// textuual representaitons separated by a single newline. | [
"renderEachChild",
"visits",
"each",
"direct",
"child",
"of",
"a",
"node",
"and",
"collects",
"the",
"sequence",
"of",
"textuual",
"representaitons",
"separated",
"by",
"a",
"single",
"newline",
"."
] | 01ec452cbe43774f989516272881441cae40c16b | https://github.com/jaytaylor/html2text/blob/01ec452cbe43774f989516272881441cae40c16b/html2text.go#L508-L525 |
30,469 | sparrc/go-ping | ping.go | NewPinger | func NewPinger(addr string) (*Pinger, error) {
ipaddr, err := net.ResolveIPAddr("ip", addr)
if err != nil {
return nil, err
}
var ipv4 bool
if isIPv4(ipaddr.IP) {
ipv4 = true
} else if isIPv6(ipaddr.IP) {
ipv4 = false
}
r := rand.New(rand.NewSource(time.Now().UnixNano()))
return &Pinger{
ipaddr: ip... | go | func NewPinger(addr string) (*Pinger, error) {
ipaddr, err := net.ResolveIPAddr("ip", addr)
if err != nil {
return nil, err
}
var ipv4 bool
if isIPv4(ipaddr.IP) {
ipv4 = true
} else if isIPv6(ipaddr.IP) {
ipv4 = false
}
r := rand.New(rand.NewSource(time.Now().UnixNano()))
return &Pinger{
ipaddr: ip... | [
"func",
"NewPinger",
"(",
"addr",
"string",
")",
"(",
"*",
"Pinger",
",",
"error",
")",
"{",
"ipaddr",
",",
"err",
":=",
"net",
".",
"ResolveIPAddr",
"(",
"\"",
"\"",
",",
"addr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"e... | // NewPinger returns a new Pinger struct pointer | [
"NewPinger",
"returns",
"a",
"new",
"Pinger",
"struct",
"pointer"
] | ef3ab45e41b017889941ea5bb796dd502d2b5a1b | https://github.com/sparrc/go-ping/blob/ef3ab45e41b017889941ea5bb796dd502d2b5a1b/ping.go#L73-L100 |
30,470 | sparrc/go-ping | ping.go | SetIPAddr | func (p *Pinger) SetIPAddr(ipaddr *net.IPAddr) {
var ipv4 bool
if isIPv4(ipaddr.IP) {
ipv4 = true
} else if isIPv6(ipaddr.IP) {
ipv4 = false
}
p.ipaddr = ipaddr
p.addr = ipaddr.String()
p.ipv4 = ipv4
} | go | func (p *Pinger) SetIPAddr(ipaddr *net.IPAddr) {
var ipv4 bool
if isIPv4(ipaddr.IP) {
ipv4 = true
} else if isIPv6(ipaddr.IP) {
ipv4 = false
}
p.ipaddr = ipaddr
p.addr = ipaddr.String()
p.ipv4 = ipv4
} | [
"func",
"(",
"p",
"*",
"Pinger",
")",
"SetIPAddr",
"(",
"ipaddr",
"*",
"net",
".",
"IPAddr",
")",
"{",
"var",
"ipv4",
"bool",
"\n",
"if",
"isIPv4",
"(",
"ipaddr",
".",
"IP",
")",
"{",
"ipv4",
"=",
"true",
"\n",
"}",
"else",
"if",
"isIPv6",
"(",
... | // SetIPAddr sets the ip address of the target host. | [
"SetIPAddr",
"sets",
"the",
"ip",
"address",
"of",
"the",
"target",
"host",
"."
] | ef3ab45e41b017889941ea5bb796dd502d2b5a1b | https://github.com/sparrc/go-ping/blob/ef3ab45e41b017889941ea5bb796dd502d2b5a1b/ping.go#L213-L224 |
30,471 | sparrc/go-ping | ping.go | Statistics | func (p *Pinger) Statistics() *Statistics {
loss := float64(p.PacketsSent-p.PacketsRecv) / float64(p.PacketsSent) * 100
var min, max, total time.Duration
if len(p.rtts) > 0 {
min = p.rtts[0]
max = p.rtts[0]
}
for _, rtt := range p.rtts {
if rtt < min {
min = rtt
}
if rtt > max {
max = rtt
}
tot... | go | func (p *Pinger) Statistics() *Statistics {
loss := float64(p.PacketsSent-p.PacketsRecv) / float64(p.PacketsSent) * 100
var min, max, total time.Duration
if len(p.rtts) > 0 {
min = p.rtts[0]
max = p.rtts[0]
}
for _, rtt := range p.rtts {
if rtt < min {
min = rtt
}
if rtt > max {
max = rtt
}
tot... | [
"func",
"(",
"p",
"*",
"Pinger",
")",
"Statistics",
"(",
")",
"*",
"Statistics",
"{",
"loss",
":=",
"float64",
"(",
"p",
".",
"PacketsSent",
"-",
"p",
".",
"PacketsRecv",
")",
"/",
"float64",
"(",
"p",
".",
"PacketsSent",
")",
"*",
"100",
"\n",
"va... | // Statistics returns the statistics of the pinger. This can be run while the
// pinger is running or after it is finished. OnFinish calls this function to
// get it's finished statistics. | [
"Statistics",
"returns",
"the",
"statistics",
"of",
"the",
"pinger",
".",
"This",
"can",
"be",
"run",
"while",
"the",
"pinger",
"is",
"running",
"or",
"after",
"it",
"is",
"finished",
".",
"OnFinish",
"calls",
"this",
"function",
"to",
"get",
"it",
"s",
... | ef3ab45e41b017889941ea5bb796dd502d2b5a1b | https://github.com/sparrc/go-ping/blob/ef3ab45e41b017889941ea5bb796dd502d2b5a1b/ping.go#L349-L385 |
30,472 | Azure/go-autorest | autorest/preparer.go | Prepare | func (pf PreparerFunc) Prepare(r *http.Request) (*http.Request, error) {
return pf(r)
} | go | func (pf PreparerFunc) Prepare(r *http.Request) (*http.Request, error) {
return pf(r)
} | [
"func",
"(",
"pf",
"PreparerFunc",
")",
"Prepare",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"return",
"pf",
"(",
"r",
")",
"\n",
"}"
] | // Prepare implements the Preparer interface on PreparerFunc. | [
"Prepare",
"implements",
"the",
"Preparer",
"interface",
"on",
"PreparerFunc",
"."
] | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/preparer.go#L51-L53 |
30,473 | Azure/go-autorest | autorest/preparer.go | CreatePreparer | func CreatePreparer(decorators ...PrepareDecorator) Preparer {
return DecoratePreparer(
Preparer(PreparerFunc(func(r *http.Request) (*http.Request, error) { return r, nil })),
decorators...)
} | go | func CreatePreparer(decorators ...PrepareDecorator) Preparer {
return DecoratePreparer(
Preparer(PreparerFunc(func(r *http.Request) (*http.Request, error) { return r, nil })),
decorators...)
} | [
"func",
"CreatePreparer",
"(",
"decorators",
"...",
"PrepareDecorator",
")",
"Preparer",
"{",
"return",
"DecoratePreparer",
"(",
"Preparer",
"(",
"PreparerFunc",
"(",
"func",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"http",
".",
"Request",
",",
... | // CreatePreparer creates, decorates, and returns a Preparer.
// Without decorators, the returned Preparer returns the passed http.Request unmodified.
// Preparers are safe to share and re-use. | [
"CreatePreparer",
"creates",
"decorates",
"and",
"returns",
"a",
"Preparer",
".",
"Without",
"decorators",
"the",
"returned",
"Preparer",
"returns",
"the",
"passed",
"http",
".",
"Request",
"unmodified",
".",
"Preparers",
"are",
"safe",
"to",
"share",
"and",
"re... | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/preparer.go#L62-L66 |
30,474 | Azure/go-autorest | autorest/preparer.go | Prepare | func Prepare(r *http.Request, decorators ...PrepareDecorator) (*http.Request, error) {
if r == nil {
return nil, NewError("autorest", "Prepare", "Invoked without an http.Request")
}
return CreatePreparer(decorators...).Prepare(r)
} | go | func Prepare(r *http.Request, decorators ...PrepareDecorator) (*http.Request, error) {
if r == nil {
return nil, NewError("autorest", "Prepare", "Invoked without an http.Request")
}
return CreatePreparer(decorators...).Prepare(r)
} | [
"func",
"Prepare",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"decorators",
"...",
"PrepareDecorator",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"if",
"r",
"==",
"nil",
"{",
"return",
"nil",
",",
"NewError",
"(",
"\"",
"\"",
"... | // Prepare accepts an http.Request and a, possibly empty, set of PrepareDecorators.
// It creates a Preparer from the decorators which it then applies to the passed http.Request. | [
"Prepare",
"accepts",
"an",
"http",
".",
"Request",
"and",
"a",
"possibly",
"empty",
"set",
"of",
"PrepareDecorators",
".",
"It",
"creates",
"a",
"Preparer",
"from",
"the",
"decorators",
"which",
"it",
"then",
"applies",
"to",
"the",
"passed",
"http",
".",
... | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/preparer.go#L81-L86 |
30,475 | Azure/go-autorest | autorest/preparer.go | WithNothing | func WithNothing() PrepareDecorator {
return func(p Preparer) Preparer {
return PreparerFunc(func(r *http.Request) (*http.Request, error) {
return p.Prepare(r)
})
}
} | go | func WithNothing() PrepareDecorator {
return func(p Preparer) Preparer {
return PreparerFunc(func(r *http.Request) (*http.Request, error) {
return p.Prepare(r)
})
}
} | [
"func",
"WithNothing",
"(",
")",
"PrepareDecorator",
"{",
"return",
"func",
"(",
"p",
"Preparer",
")",
"Preparer",
"{",
"return",
"PreparerFunc",
"(",
"func",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
"... | // WithNothing returns a "do nothing" PrepareDecorator that makes no changes to the passed
// http.Request. | [
"WithNothing",
"returns",
"a",
"do",
"nothing",
"PrepareDecorator",
"that",
"makes",
"no",
"changes",
"to",
"the",
"passed",
"http",
".",
"Request",
"."
] | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/preparer.go#L90-L96 |
30,476 | Azure/go-autorest | autorest/preparer.go | WithMethod | func WithMethod(method string) PrepareDecorator {
return func(p Preparer) Preparer {
return PreparerFunc(func(r *http.Request) (*http.Request, error) {
r.Method = method
return p.Prepare(r)
})
}
} | go | func WithMethod(method string) PrepareDecorator {
return func(p Preparer) Preparer {
return PreparerFunc(func(r *http.Request) (*http.Request, error) {
r.Method = method
return p.Prepare(r)
})
}
} | [
"func",
"WithMethod",
"(",
"method",
"string",
")",
"PrepareDecorator",
"{",
"return",
"func",
"(",
"p",
"Preparer",
")",
"Preparer",
"{",
"return",
"PreparerFunc",
"(",
"func",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"http",
".",
"Request"... | // WithMethod returns a PrepareDecorator that sets the HTTP method of the passed request. The
// decorator does not validate that the passed method string is a known HTTP method. | [
"WithMethod",
"returns",
"a",
"PrepareDecorator",
"that",
"sets",
"the",
"HTTP",
"method",
"of",
"the",
"passed",
"request",
".",
"The",
"decorator",
"does",
"not",
"validate",
"that",
"the",
"passed",
"method",
"string",
"is",
"a",
"known",
"HTTP",
"method",
... | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/preparer.go#L175-L182 |
30,477 | Azure/go-autorest | autorest/preparer.go | WithBaseURL | func WithBaseURL(baseURL string) PrepareDecorator {
return func(p Preparer) Preparer {
return PreparerFunc(func(r *http.Request) (*http.Request, error) {
r, err := p.Prepare(r)
if err == nil {
var u *url.URL
if u, err = url.Parse(baseURL); err != nil {
return r, err
}
if u.Scheme == "" {
... | go | func WithBaseURL(baseURL string) PrepareDecorator {
return func(p Preparer) Preparer {
return PreparerFunc(func(r *http.Request) (*http.Request, error) {
r, err := p.Prepare(r)
if err == nil {
var u *url.URL
if u, err = url.Parse(baseURL); err != nil {
return r, err
}
if u.Scheme == "" {
... | [
"func",
"WithBaseURL",
"(",
"baseURL",
"string",
")",
"PrepareDecorator",
"{",
"return",
"func",
"(",
"p",
"Preparer",
")",
"Preparer",
"{",
"return",
"PreparerFunc",
"(",
"func",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"http",
".",
"Reques... | // WithBaseURL returns a PrepareDecorator that populates the http.Request with a url.URL constructed
// from the supplied baseUrl. | [
"WithBaseURL",
"returns",
"a",
"PrepareDecorator",
"that",
"populates",
"the",
"http",
".",
"Request",
"with",
"a",
"url",
".",
"URL",
"constructed",
"from",
"the",
"supplied",
"baseUrl",
"."
] | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/preparer.go#L207-L226 |
30,478 | Azure/go-autorest | autorest/preparer.go | WithFile | func WithFile(f io.ReadCloser) PrepareDecorator {
return func(p Preparer) Preparer {
return PreparerFunc(func(r *http.Request) (*http.Request, error) {
r, err := p.Prepare(r)
if err == nil {
b, err := ioutil.ReadAll(f)
if err != nil {
return r, err
}
r.Body = ioutil.NopCloser(bytes.NewRead... | go | func WithFile(f io.ReadCloser) PrepareDecorator {
return func(p Preparer) Preparer {
return PreparerFunc(func(r *http.Request) (*http.Request, error) {
r, err := p.Prepare(r)
if err == nil {
b, err := ioutil.ReadAll(f)
if err != nil {
return r, err
}
r.Body = ioutil.NopCloser(bytes.NewRead... | [
"func",
"WithFile",
"(",
"f",
"io",
".",
"ReadCloser",
")",
"PrepareDecorator",
"{",
"return",
"func",
"(",
"p",
"Preparer",
")",
"Preparer",
"{",
"return",
"PreparerFunc",
"(",
"func",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"http",
".",... | // WithFile returns a PrepareDecorator that sends file in request body. | [
"WithFile",
"returns",
"a",
"PrepareDecorator",
"that",
"sends",
"file",
"in",
"request",
"body",
"."
] | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/preparer.go#L300-L315 |
30,479 | Azure/go-autorest | autorest/preparer.go | WithString | func WithString(v string) PrepareDecorator {
return func(p Preparer) Preparer {
return PreparerFunc(func(r *http.Request) (*http.Request, error) {
r, err := p.Prepare(r)
if err == nil {
r.ContentLength = int64(len(v))
r.Body = ioutil.NopCloser(strings.NewReader(v))
}
return r, err
})
}
} | go | func WithString(v string) PrepareDecorator {
return func(p Preparer) Preparer {
return PreparerFunc(func(r *http.Request) (*http.Request, error) {
r, err := p.Prepare(r)
if err == nil {
r.ContentLength = int64(len(v))
r.Body = ioutil.NopCloser(strings.NewReader(v))
}
return r, err
})
}
} | [
"func",
"WithString",
"(",
"v",
"string",
")",
"PrepareDecorator",
"{",
"return",
"func",
"(",
"p",
"Preparer",
")",
"Preparer",
"{",
"return",
"PreparerFunc",
"(",
"func",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"http",
".",
"Request",
"... | // WithString returns a PrepareDecorator that encodes the passed string into the body of the request
// and sets the Content-Length header. | [
"WithString",
"returns",
"a",
"PrepareDecorator",
"that",
"encodes",
"the",
"passed",
"string",
"into",
"the",
"body",
"of",
"the",
"request",
"and",
"sets",
"the",
"Content",
"-",
"Length",
"header",
"."
] | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/preparer.go#L349-L360 |
30,480 | Azure/go-autorest | autorest/preparer.go | WithJSON | func WithJSON(v interface{}) PrepareDecorator {
return func(p Preparer) Preparer {
return PreparerFunc(func(r *http.Request) (*http.Request, error) {
r, err := p.Prepare(r)
if err == nil {
b, err := json.Marshal(v)
if err == nil {
r.ContentLength = int64(len(b))
r.Body = ioutil.NopCloser(byte... | go | func WithJSON(v interface{}) PrepareDecorator {
return func(p Preparer) Preparer {
return PreparerFunc(func(r *http.Request) (*http.Request, error) {
r, err := p.Prepare(r)
if err == nil {
b, err := json.Marshal(v)
if err == nil {
r.ContentLength = int64(len(b))
r.Body = ioutil.NopCloser(byte... | [
"func",
"WithJSON",
"(",
"v",
"interface",
"{",
"}",
")",
"PrepareDecorator",
"{",
"return",
"func",
"(",
"p",
"Preparer",
")",
"Preparer",
"{",
"return",
"PreparerFunc",
"(",
"func",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"http",
".",
... | // WithJSON returns a PrepareDecorator that encodes the data passed as JSON into the body of the
// request and sets the Content-Length header. | [
"WithJSON",
"returns",
"a",
"PrepareDecorator",
"that",
"encodes",
"the",
"data",
"passed",
"as",
"JSON",
"into",
"the",
"body",
"of",
"the",
"request",
"and",
"sets",
"the",
"Content",
"-",
"Length",
"header",
"."
] | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/preparer.go#L364-L378 |
30,481 | Azure/go-autorest | autorest/azure/environments.go | EnvironmentFromName | func EnvironmentFromName(name string) (Environment, error) {
// IMPORTANT
// As per @radhikagupta5:
// This is technical debt, fundamentally here because Kubernetes is not currently accepting
// contributions to the providers. Once that is an option, the provider should be updated to
// directly call `EnvironmentF... | go | func EnvironmentFromName(name string) (Environment, error) {
// IMPORTANT
// As per @radhikagupta5:
// This is technical debt, fundamentally here because Kubernetes is not currently accepting
// contributions to the providers. Once that is an option, the provider should be updated to
// directly call `EnvironmentF... | [
"func",
"EnvironmentFromName",
"(",
"name",
"string",
")",
"(",
"Environment",
",",
"error",
")",
"{",
"// IMPORTANT",
"// As per @radhikagupta5:",
"// This is technical debt, fundamentally here because Kubernetes is not currently accepting",
"// contributions to the providers. Once th... | // EnvironmentFromName returns an Environment based on the common name specified. | [
"EnvironmentFromName",
"returns",
"an",
"Environment",
"based",
"on",
"the",
"common",
"name",
"specified",
"."
] | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/environments.go#L207-L225 |
30,482 | Azure/go-autorest | autorest/azure/environments.go | EnvironmentFromFile | func EnvironmentFromFile(location string) (unmarshaled Environment, err error) {
fileContents, err := ioutil.ReadFile(location)
if err != nil {
return
}
err = json.Unmarshal(fileContents, &unmarshaled)
return
} | go | func EnvironmentFromFile(location string) (unmarshaled Environment, err error) {
fileContents, err := ioutil.ReadFile(location)
if err != nil {
return
}
err = json.Unmarshal(fileContents, &unmarshaled)
return
} | [
"func",
"EnvironmentFromFile",
"(",
"location",
"string",
")",
"(",
"unmarshaled",
"Environment",
",",
"err",
"error",
")",
"{",
"fileContents",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"location",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return... | // EnvironmentFromFile loads an Environment from a configuration file available on disk.
// This function is particularly useful in the Hybrid Cloud model, where one must define their own
// endpoints. | [
"EnvironmentFromFile",
"loads",
"an",
"Environment",
"from",
"a",
"configuration",
"file",
"available",
"on",
"disk",
".",
"This",
"function",
"is",
"particularly",
"useful",
"in",
"the",
"Hybrid",
"Cloud",
"model",
"where",
"one",
"must",
"define",
"their",
"ow... | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/environments.go#L230-L239 |
30,483 | Azure/go-autorest | autorest/responder.go | Respond | func Respond(r *http.Response, decorators ...RespondDecorator) error {
if r == nil {
return nil
}
return CreateResponder(decorators...).Respond(r)
} | go | func Respond(r *http.Response, decorators ...RespondDecorator) error {
if r == nil {
return nil
}
return CreateResponder(decorators...).Respond(r)
} | [
"func",
"Respond",
"(",
"r",
"*",
"http",
".",
"Response",
",",
"decorators",
"...",
"RespondDecorator",
")",
"error",
"{",
"if",
"r",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"CreateResponder",
"(",
"decorators",
"...",
")",
".",
... | // Respond accepts an http.Response and a, possibly empty, set of RespondDecorators.
// It creates a Responder from the decorators it then applies to the passed http.Response. | [
"Respond",
"accepts",
"an",
"http",
".",
"Response",
"and",
"a",
"possibly",
"empty",
"set",
"of",
"RespondDecorators",
".",
"It",
"creates",
"a",
"Responder",
"from",
"the",
"decorators",
"it",
"then",
"applies",
"to",
"the",
"passed",
"http",
".",
"Respons... | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/responder.go#L74-L79 |
30,484 | Azure/go-autorest | autorest/responder.go | ByIgnoring | func ByIgnoring() RespondDecorator {
return func(r Responder) Responder {
return ResponderFunc(func(resp *http.Response) error {
return r.Respond(resp)
})
}
} | go | func ByIgnoring() RespondDecorator {
return func(r Responder) Responder {
return ResponderFunc(func(resp *http.Response) error {
return r.Respond(resp)
})
}
} | [
"func",
"ByIgnoring",
"(",
")",
"RespondDecorator",
"{",
"return",
"func",
"(",
"r",
"Responder",
")",
"Responder",
"{",
"return",
"ResponderFunc",
"(",
"func",
"(",
"resp",
"*",
"http",
".",
"Response",
")",
"error",
"{",
"return",
"r",
".",
"Respond",
... | // ByIgnoring returns a RespondDecorator that ignores the passed http.Response passing it unexamined
// to the next RespondDecorator. | [
"ByIgnoring",
"returns",
"a",
"RespondDecorator",
"that",
"ignores",
"the",
"passed",
"http",
".",
"Response",
"passing",
"it",
"unexamined",
"to",
"the",
"next",
"RespondDecorator",
"."
] | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/responder.go#L83-L89 |
30,485 | Azure/go-autorest | autorest/responder.go | ByCopying | func ByCopying(b *bytes.Buffer) RespondDecorator {
return func(r Responder) Responder {
return ResponderFunc(func(resp *http.Response) error {
err := r.Respond(resp)
if err == nil && resp != nil && resp.Body != nil {
resp.Body = TeeReadCloser(resp.Body, b)
}
return err
})
}
} | go | func ByCopying(b *bytes.Buffer) RespondDecorator {
return func(r Responder) Responder {
return ResponderFunc(func(resp *http.Response) error {
err := r.Respond(resp)
if err == nil && resp != nil && resp.Body != nil {
resp.Body = TeeReadCloser(resp.Body, b)
}
return err
})
}
} | [
"func",
"ByCopying",
"(",
"b",
"*",
"bytes",
".",
"Buffer",
")",
"RespondDecorator",
"{",
"return",
"func",
"(",
"r",
"Responder",
")",
"Responder",
"{",
"return",
"ResponderFunc",
"(",
"func",
"(",
"resp",
"*",
"http",
".",
"Response",
")",
"error",
"{"... | // ByCopying copies the contents of the http.Response Body into the passed bytes.Buffer as
// the Body is read. | [
"ByCopying",
"copies",
"the",
"contents",
"of",
"the",
"http",
".",
"Response",
"Body",
"into",
"the",
"passed",
"bytes",
".",
"Buffer",
"as",
"the",
"Body",
"is",
"read",
"."
] | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/responder.go#L93-L103 |
30,486 | Azure/go-autorest | autorest/responder.go | ByClosing | func ByClosing() RespondDecorator {
return func(r Responder) Responder {
return ResponderFunc(func(resp *http.Response) error {
err := r.Respond(resp)
if resp != nil && resp.Body != nil {
if err := resp.Body.Close(); err != nil {
return fmt.Errorf("Error closing the response body: %v", err)
}
}... | go | func ByClosing() RespondDecorator {
return func(r Responder) Responder {
return ResponderFunc(func(resp *http.Response) error {
err := r.Respond(resp)
if resp != nil && resp.Body != nil {
if err := resp.Body.Close(); err != nil {
return fmt.Errorf("Error closing the response body: %v", err)
}
}... | [
"func",
"ByClosing",
"(",
")",
"RespondDecorator",
"{",
"return",
"func",
"(",
"r",
"Responder",
")",
"Responder",
"{",
"return",
"ResponderFunc",
"(",
"func",
"(",
"resp",
"*",
"http",
".",
"Response",
")",
"error",
"{",
"err",
":=",
"r",
".",
"Respond"... | // ByClosing returns a RespondDecorator that first invokes the passed Responder after which it
// closes the response body. Since the passed Responder is invoked prior to closing the response
// body, the decorator may occur anywhere within the set. | [
"ByClosing",
"returns",
"a",
"RespondDecorator",
"that",
"first",
"invokes",
"the",
"passed",
"Responder",
"after",
"which",
"it",
"closes",
"the",
"response",
"body",
".",
"Since",
"the",
"passed",
"Responder",
"is",
"invoked",
"prior",
"to",
"closing",
"the",
... | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/responder.go#L126-L138 |
30,487 | Azure/go-autorest | autorest/responder.go | ByUnmarshallingJSON | func ByUnmarshallingJSON(v interface{}) RespondDecorator {
return func(r Responder) Responder {
return ResponderFunc(func(resp *http.Response) error {
err := r.Respond(resp)
if err == nil {
b, errInner := ioutil.ReadAll(resp.Body)
// Some responses might include a BOM, remove for successful unmarshalli... | go | func ByUnmarshallingJSON(v interface{}) RespondDecorator {
return func(r Responder) Responder {
return ResponderFunc(func(resp *http.Response) error {
err := r.Respond(resp)
if err == nil {
b, errInner := ioutil.ReadAll(resp.Body)
// Some responses might include a BOM, remove for successful unmarshalli... | [
"func",
"ByUnmarshallingJSON",
"(",
"v",
"interface",
"{",
"}",
")",
"RespondDecorator",
"{",
"return",
"func",
"(",
"r",
"Responder",
")",
"Responder",
"{",
"return",
"ResponderFunc",
"(",
"func",
"(",
"resp",
"*",
"http",
".",
"Response",
")",
"error",
"... | // ByUnmarshallingJSON returns a RespondDecorator that decodes a JSON document returned in the
// response Body into the value pointed to by v. | [
"ByUnmarshallingJSON",
"returns",
"a",
"RespondDecorator",
"that",
"decodes",
"a",
"JSON",
"document",
"returned",
"in",
"the",
"response",
"Body",
"into",
"the",
"value",
"pointed",
"to",
"by",
"v",
"."
] | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/responder.go#L158-L178 |
30,488 | Azure/go-autorest | autorest/responder.go | ByUnmarshallingXML | func ByUnmarshallingXML(v interface{}) RespondDecorator {
return func(r Responder) Responder {
return ResponderFunc(func(resp *http.Response) error {
err := r.Respond(resp)
if err == nil {
b, errInner := ioutil.ReadAll(resp.Body)
if errInner != nil {
err = fmt.Errorf("Error occurred reading http.R... | go | func ByUnmarshallingXML(v interface{}) RespondDecorator {
return func(r Responder) Responder {
return ResponderFunc(func(resp *http.Response) error {
err := r.Respond(resp)
if err == nil {
b, errInner := ioutil.ReadAll(resp.Body)
if errInner != nil {
err = fmt.Errorf("Error occurred reading http.R... | [
"func",
"ByUnmarshallingXML",
"(",
"v",
"interface",
"{",
"}",
")",
"RespondDecorator",
"{",
"return",
"func",
"(",
"r",
"Responder",
")",
"Responder",
"{",
"return",
"ResponderFunc",
"(",
"func",
"(",
"resp",
"*",
"http",
".",
"Response",
")",
"error",
"{... | // ByUnmarshallingXML returns a RespondDecorator that decodes a XML document returned in the
// response Body into the value pointed to by v. | [
"ByUnmarshallingXML",
"returns",
"a",
"RespondDecorator",
"that",
"decodes",
"a",
"XML",
"document",
"returned",
"in",
"the",
"response",
"Body",
"into",
"the",
"value",
"pointed",
"to",
"by",
"v",
"."
] | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/responder.go#L182-L200 |
30,489 | Azure/go-autorest | autorest/responder.go | WithErrorUnlessStatusCode | func WithErrorUnlessStatusCode(codes ...int) RespondDecorator {
return func(r Responder) Responder {
return ResponderFunc(func(resp *http.Response) error {
err := r.Respond(resp)
if err == nil && !ResponseHasStatusCode(resp, codes...) {
derr := NewErrorWithResponse("autorest", "WithErrorUnlessStatusCode", ... | go | func WithErrorUnlessStatusCode(codes ...int) RespondDecorator {
return func(r Responder) Responder {
return ResponderFunc(func(resp *http.Response) error {
err := r.Respond(resp)
if err == nil && !ResponseHasStatusCode(resp, codes...) {
derr := NewErrorWithResponse("autorest", "WithErrorUnlessStatusCode", ... | [
"func",
"WithErrorUnlessStatusCode",
"(",
"codes",
"...",
"int",
")",
"RespondDecorator",
"{",
"return",
"func",
"(",
"r",
"Responder",
")",
"Responder",
"{",
"return",
"ResponderFunc",
"(",
"func",
"(",
"resp",
"*",
"http",
".",
"Response",
")",
"error",
"{... | // WithErrorUnlessStatusCode returns a RespondDecorator that emits an error unless the response
// StatusCode is among the set passed. On error, response body is fully read into a buffer and
// presented in the returned error, as well as in the response body. | [
"WithErrorUnlessStatusCode",
"returns",
"a",
"RespondDecorator",
"that",
"emits",
"an",
"error",
"unless",
"the",
"response",
"StatusCode",
"is",
"among",
"the",
"set",
"passed",
".",
"On",
"error",
"response",
"body",
"is",
"fully",
"read",
"into",
"a",
"buffer... | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/responder.go#L205-L225 |
30,490 | Azure/go-autorest | autorest/responder.go | ExtractHeader | func ExtractHeader(header string, resp *http.Response) []string {
if resp != nil && resp.Header != nil {
return resp.Header[http.CanonicalHeaderKey(header)]
}
return nil
} | go | func ExtractHeader(header string, resp *http.Response) []string {
if resp != nil && resp.Header != nil {
return resp.Header[http.CanonicalHeaderKey(header)]
}
return nil
} | [
"func",
"ExtractHeader",
"(",
"header",
"string",
",",
"resp",
"*",
"http",
".",
"Response",
")",
"[",
"]",
"string",
"{",
"if",
"resp",
"!=",
"nil",
"&&",
"resp",
".",
"Header",
"!=",
"nil",
"{",
"return",
"resp",
".",
"Header",
"[",
"http",
".",
... | // ExtractHeader extracts all values of the specified header from the http.Response. It returns an
// empty string slice if the passed http.Response is nil or the header does not exist. | [
"ExtractHeader",
"extracts",
"all",
"values",
"of",
"the",
"specified",
"header",
"from",
"the",
"http",
".",
"Response",
".",
"It",
"returns",
"an",
"empty",
"string",
"slice",
"if",
"the",
"passed",
"http",
".",
"Response",
"is",
"nil",
"or",
"the",
"hea... | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/responder.go#L235-L240 |
30,491 | Azure/go-autorest | autorest/responder.go | ExtractHeaderValue | func ExtractHeaderValue(header string, resp *http.Response) string {
h := ExtractHeader(header, resp)
if len(h) > 0 {
return h[0]
}
return ""
} | go | func ExtractHeaderValue(header string, resp *http.Response) string {
h := ExtractHeader(header, resp)
if len(h) > 0 {
return h[0]
}
return ""
} | [
"func",
"ExtractHeaderValue",
"(",
"header",
"string",
",",
"resp",
"*",
"http",
".",
"Response",
")",
"string",
"{",
"h",
":=",
"ExtractHeader",
"(",
"header",
",",
"resp",
")",
"\n",
"if",
"len",
"(",
"h",
")",
">",
"0",
"{",
"return",
"h",
"[",
... | // ExtractHeaderValue extracts the first value of the specified header from the http.Response. It
// returns an empty string if the passed http.Response is nil or the header does not exist. | [
"ExtractHeaderValue",
"extracts",
"the",
"first",
"value",
"of",
"the",
"specified",
"header",
"from",
"the",
"http",
".",
"Response",
".",
"It",
"returns",
"an",
"empty",
"string",
"if",
"the",
"passed",
"http",
".",
"Response",
"is",
"nil",
"or",
"the",
... | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/responder.go#L244-L250 |
30,492 | Azure/go-autorest | autorest/azure/azure.go | UnmarshalJSON | func (se *ServiceError) UnmarshalJSON(b []byte) error {
// per the OData v4 spec the details field must be an array of JSON objects.
// unfortunately not all services adhear to the spec and just return a single
// object instead of an array with one object. so we have to perform some
// shenanigans to accommodate ... | go | func (se *ServiceError) UnmarshalJSON(b []byte) error {
// per the OData v4 spec the details field must be an array of JSON objects.
// unfortunately not all services adhear to the spec and just return a single
// object instead of an array with one object. so we have to perform some
// shenanigans to accommodate ... | [
"func",
"(",
"se",
"*",
"ServiceError",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"// per the OData v4 spec the details field must be an array of JSON objects.",
"// unfortunately not all services adhear to the spec and just return a single",
"// object i... | // UnmarshalJSON implements the json.Unmarshaler interface for the ServiceError type. | [
"UnmarshalJSON",
"implements",
"the",
"json",
".",
"Unmarshaler",
"interface",
"for",
"the",
"ServiceError",
"type",
"."
] | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/azure.go#L90-L130 |
30,493 | Azure/go-autorest | autorest/azure/azure.go | Error | func (e RequestError) Error() string {
return fmt.Sprintf("autorest/azure: Service returned an error. Status=%v %v",
e.StatusCode, e.ServiceError)
} | go | func (e RequestError) Error() string {
return fmt.Sprintf("autorest/azure: Service returned an error. Status=%v %v",
e.StatusCode, e.ServiceError)
} | [
"func",
"(",
"e",
"RequestError",
")",
"Error",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"e",
".",
"StatusCode",
",",
"e",
".",
"ServiceError",
")",
"\n",
"}"
] | // Error returns a human-friendly error message from service error. | [
"Error",
"returns",
"a",
"human",
"-",
"friendly",
"error",
"message",
"from",
"service",
"error",
"."
] | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/azure.go#L153-L156 |
30,494 | Azure/go-autorest | autorest/azure/azure.go | WithReturnClientID | func WithReturnClientID(b bool) autorest.PrepareDecorator {
return autorest.WithHeader(HeaderReturnClientID, strconv.FormatBool(b))
} | go | func WithReturnClientID(b bool) autorest.PrepareDecorator {
return autorest.WithHeader(HeaderReturnClientID, strconv.FormatBool(b))
} | [
"func",
"WithReturnClientID",
"(",
"b",
"bool",
")",
"autorest",
".",
"PrepareDecorator",
"{",
"return",
"autorest",
".",
"WithHeader",
"(",
"HeaderReturnClientID",
",",
"strconv",
".",
"FormatBool",
"(",
"b",
")",
")",
"\n",
"}"
] | // WithReturnClientID returns a PrepareDecorator that adds an HTTP extension header of
// x-ms-return-client-request-id whose boolean value indicates if the value of the
// x-ms-client-request-id header should be included in the http.Response. | [
"WithReturnClientID",
"returns",
"a",
"PrepareDecorator",
"that",
"adds",
"an",
"HTTP",
"extension",
"header",
"of",
"x",
"-",
"ms",
"-",
"return",
"-",
"client",
"-",
"request",
"-",
"id",
"whose",
"boolean",
"value",
"indicates",
"if",
"the",
"value",
"of"... | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/azure.go#L253-L255 |
30,495 | Azure/go-autorest | autorest/azure/azure.go | WithErrorUnlessStatusCode | func WithErrorUnlessStatusCode(codes ...int) autorest.RespondDecorator {
return func(r autorest.Responder) autorest.Responder {
return autorest.ResponderFunc(func(resp *http.Response) error {
err := r.Respond(resp)
if err == nil && !autorest.ResponseHasStatusCode(resp, codes...) {
var e RequestError
de... | go | func WithErrorUnlessStatusCode(codes ...int) autorest.RespondDecorator {
return func(r autorest.Responder) autorest.Responder {
return autorest.ResponderFunc(func(resp *http.Response) error {
err := r.Respond(resp)
if err == nil && !autorest.ResponseHasStatusCode(resp, codes...) {
var e RequestError
de... | [
"func",
"WithErrorUnlessStatusCode",
"(",
"codes",
"...",
"int",
")",
"autorest",
".",
"RespondDecorator",
"{",
"return",
"func",
"(",
"r",
"autorest",
".",
"Responder",
")",
"autorest",
".",
"Responder",
"{",
"return",
"autorest",
".",
"ResponderFunc",
"(",
"... | // WithErrorUnlessStatusCode returns a RespondDecorator that emits an
// azure.RequestError by reading the response body unless the response HTTP status code
// is among the set passed.
//
// If there is a chance service may return responses other than the Azure error
// format and the response cannot be parsed into an... | [
"WithErrorUnlessStatusCode",
"returns",
"a",
"RespondDecorator",
"that",
"emits",
"an",
"azure",
".",
"RequestError",
"by",
"reading",
"the",
"response",
"body",
"unless",
"the",
"response",
"HTTP",
"status",
"code",
"is",
"among",
"the",
"set",
"passed",
".",
"... | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/azure.go#L280-L326 |
30,496 | Azure/go-autorest | autorest/azure/auth/auth.go | GetSettingsFromEnvironment | func GetSettingsFromEnvironment() (s EnvironmentSettings, err error) {
s = EnvironmentSettings{
Values: map[string]string{},
}
s.setValue(SubscriptionID)
s.setValue(TenantID)
s.setValue(ClientID)
s.setValue(ClientSecret)
s.setValue(CertificatePath)
s.setValue(CertificatePassword)
s.setValue(Username)
s.setV... | go | func GetSettingsFromEnvironment() (s EnvironmentSettings, err error) {
s = EnvironmentSettings{
Values: map[string]string{},
}
s.setValue(SubscriptionID)
s.setValue(TenantID)
s.setValue(ClientID)
s.setValue(ClientSecret)
s.setValue(CertificatePath)
s.setValue(CertificatePassword)
s.setValue(Username)
s.setV... | [
"func",
"GetSettingsFromEnvironment",
"(",
")",
"(",
"s",
"EnvironmentSettings",
",",
"err",
"error",
")",
"{",
"s",
"=",
"EnvironmentSettings",
"{",
"Values",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
",",
"}",
"\n",
"s",
".",
"setValue",
"(",... | // GetSettingsFromEnvironment returns the available authentication settings from the environment. | [
"GetSettingsFromEnvironment",
"returns",
"the",
"available",
"authentication",
"settings",
"from",
"the",
"environment",
"."
] | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L93-L116 |
30,497 | Azure/go-autorest | autorest/azure/auth/auth.go | setValue | func (settings EnvironmentSettings) setValue(key string) {
if v := os.Getenv(key); v != "" {
settings.Values[key] = v
}
} | go | func (settings EnvironmentSettings) setValue(key string) {
if v := os.Getenv(key); v != "" {
settings.Values[key] = v
}
} | [
"func",
"(",
"settings",
"EnvironmentSettings",
")",
"setValue",
"(",
"key",
"string",
")",
"{",
"if",
"v",
":=",
"os",
".",
"Getenv",
"(",
"key",
")",
";",
"v",
"!=",
"\"",
"\"",
"{",
"settings",
".",
"Values",
"[",
"key",
"]",
"=",
"v",
"\n",
"... | // adds the specified environment variable value to the Values map if it exists | [
"adds",
"the",
"specified",
"environment",
"variable",
"value",
"to",
"the",
"Values",
"map",
"if",
"it",
"exists"
] | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L124-L128 |
30,498 | Azure/go-autorest | autorest/azure/auth/auth.go | getClientAndTenant | func (settings EnvironmentSettings) getClientAndTenant() (string, string) {
clientID := settings.Values[ClientID]
tenantID := settings.Values[TenantID]
return clientID, tenantID
} | go | func (settings EnvironmentSettings) getClientAndTenant() (string, string) {
clientID := settings.Values[ClientID]
tenantID := settings.Values[TenantID]
return clientID, tenantID
} | [
"func",
"(",
"settings",
"EnvironmentSettings",
")",
"getClientAndTenant",
"(",
")",
"(",
"string",
",",
"string",
")",
"{",
"clientID",
":=",
"settings",
".",
"Values",
"[",
"ClientID",
"]",
"\n",
"tenantID",
":=",
"settings",
".",
"Values",
"[",
"TenantID"... | // helper to return client and tenant IDs | [
"helper",
"to",
"return",
"client",
"and",
"tenant",
"IDs"
] | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L131-L135 |
30,499 | Azure/go-autorest | autorest/azure/auth/auth.go | GetClientCredentials | func (settings EnvironmentSettings) GetClientCredentials() (ClientCredentialsConfig, error) {
secret := settings.Values[ClientSecret]
if secret == "" {
return ClientCredentialsConfig{}, errors.New("missing client secret")
}
clientID, tenantID := settings.getClientAndTenant()
config := NewClientCredentialsConfig(... | go | func (settings EnvironmentSettings) GetClientCredentials() (ClientCredentialsConfig, error) {
secret := settings.Values[ClientSecret]
if secret == "" {
return ClientCredentialsConfig{}, errors.New("missing client secret")
}
clientID, tenantID := settings.getClientAndTenant()
config := NewClientCredentialsConfig(... | [
"func",
"(",
"settings",
"EnvironmentSettings",
")",
"GetClientCredentials",
"(",
")",
"(",
"ClientCredentialsConfig",
",",
"error",
")",
"{",
"secret",
":=",
"settings",
".",
"Values",
"[",
"ClientSecret",
"]",
"\n",
"if",
"secret",
"==",
"\"",
"\"",
"{",
"... | // GetClientCredentials creates a config object from the available client credentials.
// An error is returned if no client credentials are available. | [
"GetClientCredentials",
"creates",
"a",
"config",
"object",
"from",
"the",
"available",
"client",
"credentials",
".",
"An",
"error",
"is",
"returned",
"if",
"no",
"client",
"credentials",
"are",
"available",
"."
] | da8db3a19ec5aba5d01f6032407abf1bb1cc15d3 | https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L139-L149 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.