code
stringlengths 11
335k
| docstring
stringlengths 20
11.8k
| func_name
stringlengths 1
100
| language
stringclasses 1
value | repo
stringclasses 245
values | path
stringlengths 4
144
| url
stringlengths 43
214
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
func unmarshalECKey(curve elliptic.Curve, pubkey []byte) (x, y *big.Int, err error) {
x, y = elliptic.Unmarshal(curve, pubkey)
if x == nil {
return nil, nil, errors.New("ssh: elliptic.Unmarshal failure")
}
if !validateECPublicKey(curve, x, y) {
return nil, nil, errors.New("ssh: public key not on curve")
}
return x, y, nil
} | unmarshalECKey parses and checks an EC key. | unmarshalECKey | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/kex.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/kex.go | BSD-3-Clause |
func validateECPublicKey(curve elliptic.Curve, x, y *big.Int) bool {
if x.Sign() == 0 && y.Sign() == 0 {
return false
}
if x.Cmp(curve.Params().P) >= 0 {
return false
}
if y.Cmp(curve.Params().P) >= 0 {
return false
}
if !curve.IsOnCurve(x, y) {
return false
}
// We don't check if N * PubKey == 0, since
//
// - the NIST curves have cofactor = 1, so this is implicit.
// (We don't foresee an implementation that supports non NIST
// curves)
//
// - for ephemeral keys, we don't need to worry about small
// subgroup attacks.
return true
} | validateECPublicKey checks that the point is a valid public key for
the given curve. See [SEC1], 3.2.2 | validateECPublicKey | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/kex.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/kex.go | BSD-3-Clause |
func (gex *dhGEXSHA) Server(c packetConn, randSource io.Reader, magics *handshakeMagics, priv Signer) (result *kexResult, err error) {
// Receive GexRequest
packet, err := c.readPacket()
if err != nil {
return
}
var kexDHGexRequest kexDHGexRequestMsg
if err = Unmarshal(packet, &kexDHGexRequest); err != nil {
return
}
// smoosh the user's preferred size into our own limits
if kexDHGexRequest.PreferedBits > dhGroupExchangeMaximumBits {
kexDHGexRequest.PreferedBits = dhGroupExchangeMaximumBits
}
if kexDHGexRequest.PreferedBits < dhGroupExchangeMinimumBits {
kexDHGexRequest.PreferedBits = dhGroupExchangeMinimumBits
}
// fix min/max if they're inconsistent. technically, we could just pout
// and hang up, but there's no harm in giving them the benefit of the
// doubt and just picking a bitsize for them.
if kexDHGexRequest.MinBits > kexDHGexRequest.PreferedBits {
kexDHGexRequest.MinBits = kexDHGexRequest.PreferedBits
}
if kexDHGexRequest.MaxBits < kexDHGexRequest.PreferedBits {
kexDHGexRequest.MaxBits = kexDHGexRequest.PreferedBits
}
// Send GexGroup
// This is the group called diffie-hellman-group14-sha1 in RFC
// 4253 and Oakley Group 14 in RFC 3526.
p, _ := new(big.Int).SetString("FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF", 16)
gex.p = p
gex.g = big.NewInt(2)
kexDHGexGroup := kexDHGexGroupMsg{
P: gex.p,
G: gex.g,
}
if err := c.writePacket(Marshal(&kexDHGexGroup)); err != nil {
return nil, err
}
// Receive GexInit
packet, err = c.readPacket()
if err != nil {
return
}
var kexDHGexInit kexDHGexInitMsg
if err = Unmarshal(packet, &kexDHGexInit); err != nil {
return
}
var pHalf = &big.Int{}
pHalf.Rsh(gex.p, 1)
y, err := rand.Int(randSource, pHalf)
if err != nil {
return
}
Y := new(big.Int).Exp(gex.g, y, gex.p)
kInt, err := gex.diffieHellman(kexDHGexInit.X, y)
if err != nil {
return nil, err
}
hostKeyBytes := priv.PublicKey().Marshal()
h := gex.hashFunc.New()
magics.write(h)
writeString(h, hostKeyBytes)
binary.Write(h, binary.BigEndian, uint32(dhGroupExchangeMinimumBits))
binary.Write(h, binary.BigEndian, uint32(dhGroupExchangePreferredBits))
binary.Write(h, binary.BigEndian, uint32(dhGroupExchangeMaximumBits))
writeInt(h, gex.p)
writeInt(h, gex.g)
writeInt(h, kexDHGexInit.X)
writeInt(h, Y)
K := make([]byte, intLength(kInt))
marshalInt(K, kInt)
h.Write(K)
H := h.Sum(nil)
// H is already a hash, but the hostkey signing will apply its
// own key-specific hash algorithm.
sig, err := signAndMarshal(priv, randSource, H)
if err != nil {
return nil, err
}
kexDHGexReply := kexDHGexReplyMsg{
HostKey: hostKeyBytes,
Y: Y,
Signature: sig,
}
packet = Marshal(&kexDHGexReply)
err = c.writePacket(packet)
return &kexResult{
H: H,
K: K,
HostKey: hostKeyBytes,
Signature: sig,
Hash: gex.hashFunc,
}, err
} | Server half implementation of the Diffie Hellman Key Exchange with SHA1 and SHA256.
This is a minimal implementation to satisfy the automated tests. | Server | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/kex.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/kex.go | BSD-3-Clause |
func (s *ServerConfig) AddHostKey(key Signer) {
for i, k := range s.hostKeys {
if k.PublicKey().Type() == key.PublicKey().Type() {
s.hostKeys[i] = key
return
}
}
s.hostKeys = append(s.hostKeys, key)
} | AddHostKey adds a private key as a host key. If an existing host
key exists with the same algorithm, it is overwritten. Each server
config must have at least one host key. | AddHostKey | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/server.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/server.go | BSD-3-Clause |
func (c *pubKeyCache) get(user string, pubKeyData []byte) (cachedPubKey, bool) {
for _, k := range c.keys {
if k.user == user && bytes.Equal(k.pubKeyData, pubKeyData) {
return k, true
}
}
return cachedPubKey{}, false
} | get returns the result for a given user/algo/key tuple. | get | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/server.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/server.go | BSD-3-Clause |
func (c *pubKeyCache) add(candidate cachedPubKey) {
if len(c.keys) < maxCachedPubKeys {
c.keys = append(c.keys, candidate)
}
} | add adds the given tuple to the cache. | add | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/server.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/server.go | BSD-3-Clause |
func NewServerConn(c net.Conn, config *ServerConfig) (*ServerConn, <-chan NewChannel, <-chan *Request, error) {
fullConf := *config
fullConf.SetDefaults()
if fullConf.MaxAuthTries == 0 {
fullConf.MaxAuthTries = 6
}
// Check if the config contains any unsupported key exchanges
for _, kex := range fullConf.KeyExchanges {
if _, ok := serverForbiddenKexAlgos[kex]; ok {
return nil, nil, nil, fmt.Errorf("ssh: unsupported key exchange %s for server", kex)
}
}
s := &connection{
sshConn: sshConn{conn: c},
}
perms, err := s.serverHandshake(&fullConf)
if err != nil {
c.Close()
return nil, nil, nil, err
}
return &ServerConn{s, perms}, s.mux.incomingChannels, s.mux.incomingRequests, nil
} | NewServerConn starts a new SSH server with c as the underlying
transport. It starts with a handshake and, if the handshake is
unsuccessful, it closes the connection and returns an error. The
Request and NewChannel channels must be serviced, or the connection
will hang.
The returned error may be of type *ServerAuthError for
authentication errors. | NewServerConn | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/server.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/server.go | BSD-3-Clause |
func signAndMarshal(k Signer, rand io.Reader, data []byte) ([]byte, error) {
sig, err := k.Sign(rand, data)
if err != nil {
return nil, err
}
return Marshal(sig), nil
} | signAndMarshal signs the data with the appropriate algorithm,
and serializes the result in SSH wire format. | signAndMarshal | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/server.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/server.go | BSD-3-Clause |
func (s *connection) serverHandshake(config *ServerConfig) (*Permissions, error) {
if len(config.hostKeys) == 0 {
return nil, errors.New("ssh: server has no host keys")
}
if !config.NoClientAuth && config.PasswordCallback == nil && config.PublicKeyCallback == nil &&
config.KeyboardInteractiveCallback == nil && (config.GSSAPIWithMICConfig == nil ||
config.GSSAPIWithMICConfig.AllowLogin == nil || config.GSSAPIWithMICConfig.Server == nil) {
return nil, errors.New("ssh: no authentication methods configured but NoClientAuth is also false")
}
if config.ServerVersion != "" {
s.serverVersion = []byte(config.ServerVersion)
} else {
s.serverVersion = []byte(packageVersion)
}
var err error
s.clientVersion, err = exchangeVersions(s.sshConn.conn, s.serverVersion)
if err != nil {
return nil, err
}
tr := newTransport(s.sshConn.conn, config.Rand, false /* not client */)
s.transport = newServerTransport(tr, s.clientVersion, s.serverVersion, config)
if err := s.transport.waitSession(); err != nil {
return nil, err
}
// We just did the key change, so the session ID is established.
s.sessionID = s.transport.getSessionID()
var packet []byte
if packet, err = s.transport.readPacket(); err != nil {
return nil, err
}
var serviceRequest serviceRequestMsg
if err = Unmarshal(packet, &serviceRequest); err != nil {
return nil, err
}
if serviceRequest.Service != serviceUserAuth {
return nil, errors.New("ssh: requested service '" + serviceRequest.Service + "' before authenticating")
}
serviceAccept := serviceAcceptMsg{
Service: serviceUserAuth,
}
if err := s.transport.writePacket(Marshal(&serviceAccept)); err != nil {
return nil, err
}
perms, err := s.serverAuthenticate(config)
if err != nil {
return nil, err
}
s.mux = newMux(s.transport)
return perms, err
} | handshake performs key exchange and user authentication. | serverHandshake | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/server.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/server.go | BSD-3-Clause |
func (c *Client) HandleChannelOpen(channelType string) <-chan NewChannel {
c.mu.Lock()
defer c.mu.Unlock()
if c.channelHandlers == nil {
// The SSH channel has been closed.
c := make(chan NewChannel)
close(c)
return c
}
ch := c.channelHandlers[channelType]
if ch != nil {
return nil
}
ch = make(chan NewChannel, chanSize)
c.channelHandlers[channelType] = ch
return ch
} | HandleChannelOpen returns a channel on which NewChannel requests
for the given type are sent. If the type already is being handled,
nil is returned. The channel is closed when the connection is closed. | HandleChannelOpen | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/client.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/client.go | BSD-3-Clause |
func NewClient(c Conn, chans <-chan NewChannel, reqs <-chan *Request) *Client {
conn := &Client{
Conn: c,
channelHandlers: make(map[string]chan NewChannel, 1),
}
go conn.handleGlobalRequests(reqs)
go conn.handleChannelOpens(chans)
go func() {
conn.Wait()
conn.forwards.closeAll()
}()
return conn
} | NewClient creates a Client on top of the given connection. | NewClient | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/client.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/client.go | BSD-3-Clause |
func NewClientConn(c net.Conn, addr string, config *ClientConfig) (Conn, <-chan NewChannel, <-chan *Request, error) {
fullConf := *config
fullConf.SetDefaults()
if fullConf.HostKeyCallback == nil {
c.Close()
return nil, nil, nil, errors.New("ssh: must specify HostKeyCallback")
}
conn := &connection{
sshConn: sshConn{conn: c},
}
if err := conn.clientHandshake(addr, &fullConf); err != nil {
c.Close()
return nil, nil, nil, fmt.Errorf("ssh: handshake failed: %v", err)
}
conn.mux = newMux(conn.transport)
return conn, conn.mux.incomingChannels, conn.mux.incomingRequests, nil
} | NewClientConn establishes an authenticated SSH connection using c
as the underlying transport. The Request and NewChannel channels
must be serviced or the connection will hang. | NewClientConn | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/client.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/client.go | BSD-3-Clause |
func (c *connection) clientHandshake(dialAddress string, config *ClientConfig) error {
if config.ClientVersion != "" {
c.clientVersion = []byte(config.ClientVersion)
} else {
c.clientVersion = []byte(packageVersion)
}
var err error
c.serverVersion, err = exchangeVersions(c.sshConn.conn, c.clientVersion)
if err != nil {
return err
}
c.transport = newClientTransport(
newTransport(c.sshConn.conn, config.Rand, true /* is client */),
c.clientVersion, c.serverVersion, config, dialAddress, c.sshConn.RemoteAddr())
if err := c.transport.waitSession(); err != nil {
return err
}
c.sessionID = c.transport.getSessionID()
return c.clientAuthenticate(config)
} | clientHandshake performs the client side key exchange. See RFC 4253 Section
7. | clientHandshake | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/client.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/client.go | BSD-3-Clause |
func verifyHostKeySignature(hostKey PublicKey, result *kexResult) error {
sig, rest, ok := parseSignatureBody(result.Signature)
if len(rest) > 0 || !ok {
return errors.New("ssh: signature parse error")
}
return hostKey.Verify(result.H, sig)
} | verifyHostKeySignature verifies the host key obtained in the key
exchange. | verifyHostKeySignature | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/client.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/client.go | BSD-3-Clause |
func (c *Client) NewSession() (*Session, error) {
ch, in, err := c.OpenChannel("session", nil)
if err != nil {
return nil, err
}
return newSession(ch, in)
} | NewSession opens a new Session for this client. (A session is a remote
execution of a program.) | NewSession | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/client.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/client.go | BSD-3-Clause |
func (c *Client) handleChannelOpens(in <-chan NewChannel) {
for ch := range in {
c.mu.Lock()
handler := c.channelHandlers[ch.ChannelType()]
c.mu.Unlock()
if handler != nil {
handler <- ch
} else {
ch.Reject(UnknownChannelType, fmt.Sprintf("unknown channel type: %v", ch.ChannelType()))
}
}
c.mu.Lock()
for _, ch := range c.channelHandlers {
close(ch)
}
c.channelHandlers = nil
c.mu.Unlock()
} | handleChannelOpens channel open messages from the remote side. | handleChannelOpens | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/client.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/client.go | BSD-3-Clause |
func Dial(network, addr string, config *ClientConfig) (*Client, error) {
conn, err := net.DialTimeout(network, addr, config.Timeout)
if err != nil {
return nil, err
}
c, chans, reqs, err := NewClientConn(conn, addr, config)
if err != nil {
return nil, err
}
return NewClient(c, chans, reqs), nil
} | Dial starts a client connection to the given SSH server. It is a
convenience function that connects to the given network address,
initiates the SSH handshake, and then sets up a Client. For access
to incoming channels and requests, use net.Dial with NewClientConn
instead. | Dial | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/client.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/client.go | BSD-3-Clause |
func InsecureIgnoreHostKey() HostKeyCallback {
return func(hostname string, remote net.Addr, key PublicKey) error {
return nil
}
} | InsecureIgnoreHostKey returns a function that can be used for
ClientConfig.HostKeyCallback to accept any host key. It should
not be used for production code. | InsecureIgnoreHostKey | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/client.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/client.go | BSD-3-Clause |
func FixedHostKey(key PublicKey) HostKeyCallback {
hk := &fixedHostKey{key}
return hk.check
} | FixedHostKey returns a function for use in
ClientConfig.HostKeyCallback to accept only a specific host key. | FixedHostKey | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/client.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/client.go | BSD-3-Clause |
func BannerDisplayStderr() BannerCallback {
return func(banner string) error {
_, err := os.Stderr.WriteString(banner)
return err
}
} | BannerDisplayStderr returns a function that can be used for
ClientConfig.BannerCallback to display banners on os.Stderr. | BannerDisplayStderr | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/client.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/client.go | BSD-3-Clause |
func (t *transport) prepareKeyChange(algs *algorithms, kexResult *kexResult) error {
ciph, err := newPacketCipher(t.reader.dir, algs.r, kexResult)
if err != nil {
return err
}
t.reader.pendingKeyChange <- ciph
ciph, err = newPacketCipher(t.writer.dir, algs.w, kexResult)
if err != nil {
return err
}
t.writer.pendingKeyChange <- ciph
return nil
} | prepareKeyChange sets up key material for a keychange. The key changes in
both directions are triggered by reading and writing a msgNewKey packet
respectively. | prepareKeyChange | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/transport.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/transport.go | BSD-3-Clause |
func (t *transport) readPacket() (p []byte, err error) {
for {
p, err = t.reader.readPacket(t.bufReader)
if err != nil {
break
}
if len(p) == 0 || (p[0] != msgIgnore && p[0] != msgDebug) {
break
}
}
if debugTransport {
t.printPacket(p, false)
}
return p, err
} | Read and decrypt next packet. | readPacket | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/transport.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/transport.go | BSD-3-Clause |
func newPacketCipher(d direction, algs directionAlgorithms, kex *kexResult) (packetCipher, error) {
cipherMode := cipherModes[algs.Cipher]
macMode := macModes[algs.MAC]
iv := make([]byte, cipherMode.ivSize)
key := make([]byte, cipherMode.keySize)
macKey := make([]byte, macMode.keySize)
generateKeyMaterial(iv, d.ivTag, kex)
generateKeyMaterial(key, d.keyTag, kex)
generateKeyMaterial(macKey, d.macKeyTag, kex)
return cipherModes[algs.Cipher].create(key, iv, macKey, algs)
} | setupKeys sets the cipher and MAC keys from kex.K, kex.H and sessionId, as
described in RFC 4253, section 6.4. direction should either be serverKeys
(to setup server->client keys) or clientKeys (for client->server keys). | newPacketCipher | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/transport.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/transport.go | BSD-3-Clause |
func generateKeyMaterial(out, tag []byte, r *kexResult) {
var digestsSoFar []byte
h := r.Hash.New()
for len(out) > 0 {
h.Reset()
h.Write(r.K)
h.Write(r.H)
if len(digestsSoFar) == 0 {
h.Write(tag)
h.Write(r.SessionID)
} else {
h.Write(digestsSoFar)
}
digest := h.Sum(nil)
n := copy(out, digest)
out = out[n:]
if len(out) > 0 {
digestsSoFar = append(digestsSoFar, digest...)
}
}
} | generateKeyMaterial fills out with key material generated from tag, K, H
and sessionId, as specified in RFC 4253, section 7.2. | generateKeyMaterial | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/transport.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/transport.go | BSD-3-Clause |
func exchangeVersions(rw io.ReadWriter, versionLine []byte) (them []byte, err error) {
// Contrary to the RFC, we do not ignore lines that don't
// start with "SSH-2.0-" to make the library usable with
// nonconforming servers.
for _, c := range versionLine {
// The spec disallows non US-ASCII chars, and
// specifically forbids null chars.
if c < 32 {
return nil, errors.New("ssh: junk character in version line")
}
}
if _, err = rw.Write(append(versionLine, '\r', '\n')); err != nil {
return
}
them, err = readVersion(rw)
return them, err
} | Sends and receives a version line. The versionLine string should
be US ASCII, start with "SSH-2.0-", and should not include a
newline. exchangeVersions returns the other side's version line. | exchangeVersions | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/transport.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/transport.go | BSD-3-Clause |
func readVersion(r io.Reader) ([]byte, error) {
versionString := make([]byte, 0, 64)
var ok bool
var buf [1]byte
for length := 0; length < maxVersionStringBytes; length++ {
_, err := io.ReadFull(r, buf[:])
if err != nil {
return nil, err
}
// The RFC says that the version should be terminated with \r\n
// but several SSH servers actually only send a \n.
if buf[0] == '\n' {
if !bytes.HasPrefix(versionString, []byte("SSH-")) {
// RFC 4253 says we need to ignore all version string lines
// except the one containing the SSH version (provided that
// all the lines do not exceed 255 bytes in total).
versionString = versionString[:0]
continue
}
ok = true
break
}
// non ASCII chars are disallowed, but we are lenient,
// since Go doesn't use null-terminated strings.
// The RFC allows a comment after a space, however,
// all of it (version and comments) goes into the
// session hash.
versionString = append(versionString, buf[0])
}
if !ok {
return nil, errors.New("ssh: overflow reading version string")
}
// There might be a '\r' on the end which we should remove.
if len(versionString) > 0 && versionString[len(versionString)-1] == '\r' {
versionString = versionString[:len(versionString)-1]
}
return versionString, nil
} | Read version string as specified by RFC 4253, section 4.2. | readVersion | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/transport.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/transport.go | BSD-3-Clause |
func buildMIC(sessionID string, username string, service string, authMethod string) []byte {
out := make([]byte, 0, 0)
out = appendString(out, sessionID)
out = append(out, msgUserAuthRequest)
out = appendString(out, username)
out = appendString(out, service)
out = appendString(out, authMethod)
return out
} | See RFC 4462 section 3.6. | buildMIC | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/ssh_gss.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/ssh_gss.go | BSD-3-Clause |
func typeTags(structType reflect.Type) (tags []byte) {
tagStr := structType.Field(0).Tag.Get("sshtype")
for _, tag := range strings.Split(tagStr, "|") {
i, err := strconv.Atoi(tag)
if err == nil {
tags = append(tags, byte(i))
}
}
return tags
} | typeTags returns the possible type bytes for the given reflect.Type, which
should be a struct. The possible values are separated by a '|' character. | typeTags | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/messages.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/messages.go | BSD-3-Clause |
func Unmarshal(data []byte, out interface{}) error {
v := reflect.ValueOf(out).Elem()
structType := v.Type()
expectedTypes := typeTags(structType)
var expectedType byte
if len(expectedTypes) > 0 {
expectedType = expectedTypes[0]
}
if len(data) == 0 {
return parseError(expectedType)
}
if len(expectedTypes) > 0 {
goodType := false
for _, e := range expectedTypes {
if e > 0 && data[0] == e {
goodType = true
break
}
}
if !goodType {
return fmt.Errorf("ssh: unexpected message type %d (expected one of %v)", data[0], expectedTypes)
}
data = data[1:]
}
var ok bool
for i := 0; i < v.NumField(); i++ {
field := v.Field(i)
t := field.Type()
switch t.Kind() {
case reflect.Bool:
if len(data) < 1 {
return errShortRead
}
field.SetBool(data[0] != 0)
data = data[1:]
case reflect.Array:
if t.Elem().Kind() != reflect.Uint8 {
return fieldError(structType, i, "array of unsupported type")
}
if len(data) < t.Len() {
return errShortRead
}
for j, n := 0, t.Len(); j < n; j++ {
field.Index(j).Set(reflect.ValueOf(data[j]))
}
data = data[t.Len():]
case reflect.Uint64:
var u64 uint64
if u64, data, ok = parseUint64(data); !ok {
return errShortRead
}
field.SetUint(u64)
case reflect.Uint32:
var u32 uint32
if u32, data, ok = parseUint32(data); !ok {
return errShortRead
}
field.SetUint(uint64(u32))
case reflect.Uint8:
if len(data) < 1 {
return errShortRead
}
field.SetUint(uint64(data[0]))
data = data[1:]
case reflect.String:
var s []byte
if s, data, ok = parseString(data); !ok {
return fieldError(structType, i, "")
}
field.SetString(string(s))
case reflect.Slice:
switch t.Elem().Kind() {
case reflect.Uint8:
if structType.Field(i).Tag.Get("ssh") == "rest" {
field.Set(reflect.ValueOf(data))
data = nil
} else {
var s []byte
if s, data, ok = parseString(data); !ok {
return errShortRead
}
field.Set(reflect.ValueOf(s))
}
case reflect.String:
var nl []string
if nl, data, ok = parseNameList(data); !ok {
return errShortRead
}
field.Set(reflect.ValueOf(nl))
default:
return fieldError(structType, i, "slice of unsupported type")
}
case reflect.Ptr:
if t == bigIntType {
var n *big.Int
if n, data, ok = parseInt(data); !ok {
return errShortRead
}
field.Set(reflect.ValueOf(n))
} else {
return fieldError(structType, i, "pointer to unsupported type")
}
default:
return fieldError(structType, i, fmt.Sprintf("unsupported type: %v", t))
}
}
if len(data) != 0 {
return parseError(expectedType)
}
return nil
} | Unmarshal parses data in SSH wire format into a structure. The out
argument should be a pointer to struct. If the first member of the
struct has the "sshtype" tag set to a '|'-separated set of numbers
in decimal, the packet must start with one of those numbers. In
case of error, Unmarshal returns a ParseError or
UnexpectedMessageError. | Unmarshal | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/messages.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/messages.go | BSD-3-Clause |
func Marshal(msg interface{}) []byte {
out := make([]byte, 0, 64)
return marshalStruct(out, msg)
} | Marshal serializes the message in msg to SSH wire format. The msg
argument should be a struct or pointer to struct. If the first
member has the "sshtype" tag set to a number in decimal, that
number is prepended to the result. If the last of member has the
"ssh" tag set to "rest", its contents are appended to the output. | Marshal | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/messages.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/messages.go | BSD-3-Clause |
func decode(packet []byte) (interface{}, error) {
var msg interface{}
switch packet[0] {
case msgDisconnect:
msg = new(disconnectMsg)
case msgServiceRequest:
msg = new(serviceRequestMsg)
case msgServiceAccept:
msg = new(serviceAcceptMsg)
case msgKexInit:
msg = new(kexInitMsg)
case msgKexDHInit:
msg = new(kexDHInitMsg)
case msgKexDHReply:
msg = new(kexDHReplyMsg)
case msgUserAuthRequest:
msg = new(userAuthRequestMsg)
case msgUserAuthSuccess:
return new(userAuthSuccessMsg), nil
case msgUserAuthFailure:
msg = new(userAuthFailureMsg)
case msgUserAuthPubKeyOk:
msg = new(userAuthPubKeyOkMsg)
case msgGlobalRequest:
msg = new(globalRequestMsg)
case msgRequestSuccess:
msg = new(globalRequestSuccessMsg)
case msgRequestFailure:
msg = new(globalRequestFailureMsg)
case msgChannelOpen:
msg = new(channelOpenMsg)
case msgChannelData:
msg = new(channelDataMsg)
case msgChannelOpenConfirm:
msg = new(channelOpenConfirmMsg)
case msgChannelOpenFailure:
msg = new(channelOpenFailureMsg)
case msgChannelWindowAdjust:
msg = new(windowAdjustMsg)
case msgChannelEOF:
msg = new(channelEOFMsg)
case msgChannelClose:
msg = new(channelCloseMsg)
case msgChannelRequest:
msg = new(channelRequestMsg)
case msgChannelSuccess:
msg = new(channelRequestSuccessMsg)
case msgChannelFailure:
msg = new(channelRequestFailureMsg)
case msgUserAuthGSSAPIToken:
msg = new(userAuthGSSAPIToken)
case msgUserAuthGSSAPIMIC:
msg = new(userAuthGSSAPIMIC)
case msgUserAuthGSSAPIErrTok:
msg = new(userAuthGSSAPIErrTok)
case msgUserAuthGSSAPIError:
msg = new(userAuthGSSAPIError)
default:
return nil, unexpectedMessageError(0, packet[0])
}
if err := Unmarshal(packet, msg); err != nil {
return nil, err
}
return msg, nil
} | Decode a packet into its corresponding message. | decode | go | flynn/flynn | vendor/golang.org/x/crypto/ssh/messages.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/ssh/messages.go | BSD-3-Clause |
func setup(subKey *[32]byte, counter *[16]byte, nonce *[24]byte, key *[32]byte) {
// We use XSalsa20 for encryption so first we need to generate a
// key and nonce with HSalsa20.
var hNonce [16]byte
copy(hNonce[:], nonce[:])
salsa.HSalsa20(subKey, &hNonce, key, &salsa.Sigma)
// The final 8 bytes of the original nonce form the new nonce.
copy(counter[:], nonce[16:])
} | setup produces a sub-key and Salsa20 counter given a nonce and key. | setup | go | flynn/flynn | vendor/golang.org/x/crypto/nacl/secretbox/secretbox.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/nacl/secretbox/secretbox.go | BSD-3-Clause |
func sliceForAppend(in []byte, n int) (head, tail []byte) {
if total := len(in) + n; cap(in) >= total {
head = in[:total]
} else {
head = make([]byte, total)
copy(head, in)
}
tail = head[len(in):]
return
} | sliceForAppend takes a slice and a requested number of bytes. It returns a
slice with the contents of the given slice followed by that many bytes and a
second slice that aliases into it and contains only the extra bytes. If the
original slice has sufficient capacity then no allocation is performed. | sliceForAppend | go | flynn/flynn | vendor/golang.org/x/crypto/nacl/secretbox/secretbox.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/nacl/secretbox/secretbox.go | BSD-3-Clause |
func Seal(out, message []byte, nonce *[24]byte, key *[32]byte) []byte {
var subKey [32]byte
var counter [16]byte
setup(&subKey, &counter, nonce, key)
// The Poly1305 key is generated by encrypting 32 bytes of zeros. Since
// Salsa20 works with 64-byte blocks, we also generate 32 bytes of
// keystream as a side effect.
var firstBlock [64]byte
salsa.XORKeyStream(firstBlock[:], firstBlock[:], &counter, &subKey)
var poly1305Key [32]byte
copy(poly1305Key[:], firstBlock[:])
ret, out := sliceForAppend(out, len(message)+poly1305.TagSize)
if subtle.AnyOverlap(out, message) {
panic("nacl: invalid buffer overlap")
}
// We XOR up to 32 bytes of message with the keystream generated from
// the first block.
firstMessageBlock := message
if len(firstMessageBlock) > 32 {
firstMessageBlock = firstMessageBlock[:32]
}
tagOut := out
out = out[poly1305.TagSize:]
for i, x := range firstMessageBlock {
out[i] = firstBlock[32+i] ^ x
}
message = message[len(firstMessageBlock):]
ciphertext := out
out = out[len(firstMessageBlock):]
// Now encrypt the rest.
counter[8] = 1
salsa.XORKeyStream(out, message, &counter, &subKey)
var tag [poly1305.TagSize]byte
poly1305.Sum(&tag, ciphertext, &poly1305Key)
copy(tagOut, tag[:])
return ret
} | Seal appends an encrypted and authenticated copy of message to out, which
must not overlap message. The key and nonce pair must be unique for each
distinct message and the output will be Overhead bytes longer than message. | Seal | go | flynn/flynn | vendor/golang.org/x/crypto/nacl/secretbox/secretbox.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/nacl/secretbox/secretbox.go | BSD-3-Clause |
func Open(out, box []byte, nonce *[24]byte, key *[32]byte) ([]byte, bool) {
if len(box) < Overhead {
return nil, false
}
var subKey [32]byte
var counter [16]byte
setup(&subKey, &counter, nonce, key)
// The Poly1305 key is generated by encrypting 32 bytes of zeros. Since
// Salsa20 works with 64-byte blocks, we also generate 32 bytes of
// keystream as a side effect.
var firstBlock [64]byte
salsa.XORKeyStream(firstBlock[:], firstBlock[:], &counter, &subKey)
var poly1305Key [32]byte
copy(poly1305Key[:], firstBlock[:])
var tag [poly1305.TagSize]byte
copy(tag[:], box)
if !poly1305.Verify(&tag, box[poly1305.TagSize:], &poly1305Key) {
return nil, false
}
ret, out := sliceForAppend(out, len(box)-Overhead)
if subtle.AnyOverlap(out, box) {
panic("nacl: invalid buffer overlap")
}
// We XOR up to 32 bytes of box with the keystream generated from
// the first block.
box = box[Overhead:]
firstMessageBlock := box
if len(firstMessageBlock) > 32 {
firstMessageBlock = firstMessageBlock[:32]
}
for i, x := range firstMessageBlock {
out[i] = firstBlock[32+i] ^ x
}
box = box[len(firstMessageBlock):]
out = out[len(firstMessageBlock):]
// Now decrypt the rest.
counter[8] = 1
salsa.XORKeyStream(out, box, &counter, &subKey)
return ret, true
} | Open authenticates and decrypts a box produced by Seal and appends the
message to out, which must not overlap box. The output will be Overhead
bytes smaller than box. | Open | go | flynn/flynn | vendor/golang.org/x/crypto/nacl/secretbox/secretbox.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/nacl/secretbox/secretbox.go | BSD-3-Clause |
func (b *Builder) AddASN1Int64(v int64) {
b.addASN1Signed(asn1.INTEGER, v)
} | AddASN1Int64 appends a DER-encoded ASN.1 INTEGER. | AddASN1Int64 | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (b *Builder) AddASN1Int64WithTag(v int64, tag asn1.Tag) {
b.addASN1Signed(tag, v)
} | AddASN1Int64WithTag appends a DER-encoded ASN.1 INTEGER with the
given tag. | AddASN1Int64WithTag | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (b *Builder) AddASN1Enum(v int64) {
b.addASN1Signed(asn1.ENUM, v)
} | AddASN1Enum appends a DER-encoded ASN.1 ENUMERATION. | AddASN1Enum | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (b *Builder) AddASN1Uint64(v uint64) {
b.AddASN1(asn1.INTEGER, func(c *Builder) {
length := 1
for i := v; i >= 0x80; i >>= 8 {
length++
}
for ; length > 0; length-- {
i := v >> uint((length-1)*8) & 0xff
c.AddUint8(uint8(i))
}
})
} | AddASN1Uint64 appends a DER-encoded ASN.1 INTEGER. | AddASN1Uint64 | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (b *Builder) AddASN1BigInt(n *big.Int) {
if b.err != nil {
return
}
b.AddASN1(asn1.INTEGER, func(c *Builder) {
if n.Sign() < 0 {
// A negative number has to be converted to two's-complement form. So we
// invert and subtract 1. If the most-significant-bit isn't set then
// we'll need to pad the beginning with 0xff in order to keep the number
// negative.
nMinus1 := new(big.Int).Neg(n)
nMinus1.Sub(nMinus1, bigOne)
bytes := nMinus1.Bytes()
for i := range bytes {
bytes[i] ^= 0xff
}
if bytes[0]&0x80 == 0 {
c.add(0xff)
}
c.add(bytes...)
} else if n.Sign() == 0 {
c.add(0)
} else {
bytes := n.Bytes()
if bytes[0]&0x80 != 0 {
c.add(0)
}
c.add(bytes...)
}
})
} | AddASN1BigInt appends a DER-encoded ASN.1 INTEGER. | AddASN1BigInt | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (b *Builder) AddASN1OctetString(bytes []byte) {
b.AddASN1(asn1.OCTET_STRING, func(c *Builder) {
c.AddBytes(bytes)
})
} | AddASN1OctetString appends a DER-encoded ASN.1 OCTET STRING. | AddASN1OctetString | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (b *Builder) AddASN1GeneralizedTime(t time.Time) {
if t.Year() < 0 || t.Year() > 9999 {
b.err = fmt.Errorf("cryptobyte: cannot represent %v as a GeneralizedTime", t)
return
}
b.AddASN1(asn1.GeneralizedTime, func(c *Builder) {
c.AddBytes([]byte(t.Format(generalizedTimeFormatStr)))
})
} | AddASN1GeneralizedTime appends a DER-encoded ASN.1 GENERALIZEDTIME. | AddASN1GeneralizedTime | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (b *Builder) AddASN1BitString(data []byte) {
b.AddASN1(asn1.BIT_STRING, func(b *Builder) {
b.AddUint8(0)
b.AddBytes(data)
})
} | AddASN1BitString appends a DER-encoded ASN.1 BIT STRING. This does not
support BIT STRINGs that are not a whole number of bytes. | AddASN1BitString | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (b *Builder) MarshalASN1(v interface{}) {
// NOTE(martinkr): This is somewhat of a hack to allow propagation of
// encoding_asn1.Marshal errors into Builder.err. N.B. if you call MarshalASN1 with a
// value embedded into a struct, its tag information is lost.
if b.err != nil {
return
}
bytes, err := encoding_asn1.Marshal(v)
if err != nil {
b.err = err
return
}
b.AddBytes(bytes)
} | MarshalASN1 calls encoding_asn1.Marshal on its input and appends the result if
successful or records an error if one occurred. | MarshalASN1 | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (b *Builder) AddASN1(tag asn1.Tag, f BuilderContinuation) {
if b.err != nil {
return
}
// Identifiers with the low five bits set indicate high-tag-number format
// (two or more octets), which we don't support.
if tag&0x1f == 0x1f {
b.err = fmt.Errorf("cryptobyte: high-tag number identifier octects not supported: 0x%x", tag)
return
}
b.AddUint8(uint8(tag))
b.addLengthPrefixed(1, true, f)
} | AddASN1 appends an ASN.1 object. The object is prefixed with the given tag.
Tags greater than 30 are not supported and result in an error (i.e.
low-tag-number form only). The child builder passed to the
BuilderContinuation can be used to build the content of the ASN.1 object. | AddASN1 | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (s *String) ReadASN1Boolean(out *bool) bool {
var bytes String
if !s.ReadASN1(&bytes, asn1.INTEGER) || len(bytes) != 1 {
return false
}
switch bytes[0] {
case 0:
*out = false
case 0xff:
*out = true
default:
return false
}
return true
} | ReadASN1Boolean decodes an ASN.1 INTEGER and converts it to a boolean
representation into out and advances. It reports whether the read
was successful. | ReadASN1Boolean | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (s *String) ReadASN1Integer(out interface{}) bool {
if reflect.TypeOf(out).Kind() != reflect.Ptr {
panic("out is not a pointer")
}
switch reflect.ValueOf(out).Elem().Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
var i int64
if !s.readASN1Int64(&i) || reflect.ValueOf(out).Elem().OverflowInt(i) {
return false
}
reflect.ValueOf(out).Elem().SetInt(i)
return true
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
var u uint64
if !s.readASN1Uint64(&u) || reflect.ValueOf(out).Elem().OverflowUint(u) {
return false
}
reflect.ValueOf(out).Elem().SetUint(u)
return true
case reflect.Struct:
if reflect.TypeOf(out).Elem() == bigIntType {
return s.readASN1BigInt(out.(*big.Int))
}
}
panic("out does not point to an integer type")
} | ReadASN1Integer decodes an ASN.1 INTEGER into out and advances. If out does
not point to an integer or to a big.Int, it panics. It reports whether the
read was successful. | ReadASN1Integer | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (s *String) ReadASN1Int64WithTag(out *int64, tag asn1.Tag) bool {
var bytes String
return s.ReadASN1(&bytes, tag) && checkASN1Integer(bytes) && asn1Signed(out, bytes)
} | ReadASN1Int64WithTag decodes an ASN.1 INTEGER with the given tag into out
and advances. It reports whether the read was successful and resulted in a
value that can be represented in an int64. | ReadASN1Int64WithTag | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (s *String) ReadASN1Enum(out *int) bool {
var bytes String
var i int64
if !s.ReadASN1(&bytes, asn1.ENUM) || !checkASN1Integer(bytes) || !asn1Signed(&i, bytes) {
return false
}
if int64(int(i)) != i {
return false
}
*out = int(i)
return true
} | ReadASN1Enum decodes an ASN.1 ENUMERATION into out and advances. It reports
whether the read was successful. | ReadASN1Enum | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (s *String) ReadASN1ObjectIdentifier(out *encoding_asn1.ObjectIdentifier) bool {
var bytes String
if !s.ReadASN1(&bytes, asn1.OBJECT_IDENTIFIER) || len(bytes) == 0 {
return false
}
// In the worst case, we get two elements from the first byte (which is
// encoded differently) and then every varint is a single byte long.
components := make([]int, len(bytes)+1)
// The first varint is 40*value1 + value2:
// According to this packing, value1 can take the values 0, 1 and 2 only.
// When value1 = 0 or value1 = 1, then value2 is <= 39. When value1 = 2,
// then there are no restrictions on value2.
var v int
if !bytes.readBase128Int(&v) {
return false
}
if v < 80 {
components[0] = v / 40
components[1] = v % 40
} else {
components[0] = 2
components[1] = v - 80
}
i := 2
for ; len(bytes) > 0; i++ {
if !bytes.readBase128Int(&v) {
return false
}
components[i] = v
}
*out = components[:i]
return true
} | ReadASN1ObjectIdentifier decodes an ASN.1 OBJECT IDENTIFIER into out and
advances. It reports whether the read was successful. | ReadASN1ObjectIdentifier | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (s *String) ReadASN1GeneralizedTime(out *time.Time) bool {
var bytes String
if !s.ReadASN1(&bytes, asn1.GeneralizedTime) {
return false
}
t := string(bytes)
res, err := time.Parse(generalizedTimeFormatStr, t)
if err != nil {
return false
}
if serialized := res.Format(generalizedTimeFormatStr); serialized != t {
return false
}
*out = res
return true
} | ReadASN1GeneralizedTime decodes an ASN.1 GENERALIZEDTIME into out and
advances. It reports whether the read was successful. | ReadASN1GeneralizedTime | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (s *String) ReadASN1BitString(out *encoding_asn1.BitString) bool {
var bytes String
if !s.ReadASN1(&bytes, asn1.BIT_STRING) || len(bytes) == 0 {
return false
}
paddingBits := uint8(bytes[0])
bytes = bytes[1:]
if paddingBits > 7 ||
len(bytes) == 0 && paddingBits != 0 ||
len(bytes) > 0 && bytes[len(bytes)-1]&(1<<paddingBits-1) != 0 {
return false
}
out.BitLength = len(bytes)*8 - int(paddingBits)
out.Bytes = bytes
return true
} | ReadASN1BitString decodes an ASN.1 BIT STRING into out and advances.
It reports whether the read was successful. | ReadASN1BitString | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (s *String) ReadASN1BitStringAsBytes(out *[]byte) bool {
var bytes String
if !s.ReadASN1(&bytes, asn1.BIT_STRING) || len(bytes) == 0 {
return false
}
paddingBits := uint8(bytes[0])
if paddingBits != 0 {
return false
}
*out = bytes[1:]
return true
} | ReadASN1BitString decodes an ASN.1 BIT STRING into out and advances. It is
an error if the BIT STRING is not a whole number of bytes. It reports
whether the read was successful. | ReadASN1BitStringAsBytes | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (s *String) ReadASN1Bytes(out *[]byte, tag asn1.Tag) bool {
return s.ReadASN1((*String)(out), tag)
} | ReadASN1Bytes reads the contents of a DER-encoded ASN.1 element (not including
tag and length bytes) into out, and advances. The element must match the
given tag. It reports whether the read was successful. | ReadASN1Bytes | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (s *String) ReadASN1(out *String, tag asn1.Tag) bool {
var t asn1.Tag
if !s.ReadAnyASN1(out, &t) || t != tag {
return false
}
return true
} | ReadASN1 reads the contents of a DER-encoded ASN.1 element (not including
tag and length bytes) into out, and advances. The element must match the
given tag. It reports whether the read was successful.
Tags greater than 30 are not supported (i.e. low-tag-number format only). | ReadASN1 | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (s *String) ReadASN1Element(out *String, tag asn1.Tag) bool {
var t asn1.Tag
if !s.ReadAnyASN1Element(out, &t) || t != tag {
return false
}
return true
} | ReadASN1Element reads the contents of a DER-encoded ASN.1 element (including
tag and length bytes) into out, and advances. The element must match the
given tag. It reports whether the read was successful.
Tags greater than 30 are not supported (i.e. low-tag-number format only). | ReadASN1Element | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (s *String) ReadAnyASN1(out *String, outTag *asn1.Tag) bool {
return s.readASN1(out, outTag, true /* skip header */)
} | ReadAnyASN1 reads the contents of a DER-encoded ASN.1 element (not including
tag and length bytes) into out, sets outTag to its tag, and advances.
It reports whether the read was successful.
Tags greater than 30 are not supported (i.e. low-tag-number format only). | ReadAnyASN1 | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (s *String) ReadAnyASN1Element(out *String, outTag *asn1.Tag) bool {
return s.readASN1(out, outTag, false /* include header */)
} | ReadAnyASN1Element reads the contents of a DER-encoded ASN.1 element
(including tag and length bytes) into out, sets outTag to is tag, and
advances. It reports whether the read was successful.
Tags greater than 30 are not supported (i.e. low-tag-number format only). | ReadAnyASN1Element | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (s String) PeekASN1Tag(tag asn1.Tag) bool {
if len(s) == 0 {
return false
}
return asn1.Tag(s[0]) == tag
} | PeekASN1Tag reports whether the next ASN.1 value on the string starts with
the given tag. | PeekASN1Tag | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (s *String) SkipASN1(tag asn1.Tag) bool {
var unused String
return s.ReadASN1(&unused, tag)
} | SkipASN1 reads and discards an ASN.1 element with the given tag. It
reports whether the operation was successful. | SkipASN1 | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (s *String) ReadOptionalASN1(out *String, outPresent *bool, tag asn1.Tag) bool {
present := s.PeekASN1Tag(tag)
if outPresent != nil {
*outPresent = present
}
if present && !s.ReadASN1(out, tag) {
return false
}
return true
} | ReadOptionalASN1 attempts to read the contents of a DER-encoded ASN.1
element (not including tag and length bytes) tagged with the given tag into
out. It stores whether an element with the tag was found in outPresent,
unless outPresent is nil. It reports whether the read was successful. | ReadOptionalASN1 | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (s *String) SkipOptionalASN1(tag asn1.Tag) bool {
if !s.PeekASN1Tag(tag) {
return true
}
var unused String
return s.ReadASN1(&unused, tag)
} | SkipOptionalASN1 advances s over an ASN.1 element with the given tag, or
else leaves s unchanged. It reports whether the operation was successful. | SkipOptionalASN1 | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (s *String) ReadOptionalASN1Integer(out interface{}, tag asn1.Tag, defaultValue interface{}) bool {
if reflect.TypeOf(out).Kind() != reflect.Ptr {
panic("out is not a pointer")
}
var present bool
var i String
if !s.ReadOptionalASN1(&i, &present, tag) {
return false
}
if !present {
switch reflect.ValueOf(out).Elem().Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
reflect.ValueOf(out).Elem().Set(reflect.ValueOf(defaultValue))
case reflect.Struct:
if reflect.TypeOf(out).Elem() != bigIntType {
panic("invalid integer type")
}
if reflect.TypeOf(defaultValue).Kind() != reflect.Ptr ||
reflect.TypeOf(defaultValue).Elem() != bigIntType {
panic("out points to big.Int, but defaultValue does not")
}
out.(*big.Int).Set(defaultValue.(*big.Int))
default:
panic("invalid integer type")
}
return true
}
if !i.ReadASN1Integer(out) || !i.Empty() {
return false
}
return true
} | ReadOptionalASN1Integer attempts to read an optional ASN.1 INTEGER
explicitly tagged with tag into out and advances. If no element with a
matching tag is present, it writes defaultValue into out instead. If out
does not point to an integer or to a big.Int, it panics. It reports
whether the read was successful. | ReadOptionalASN1Integer | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (s *String) ReadOptionalASN1OctetString(out *[]byte, outPresent *bool, tag asn1.Tag) bool {
var present bool
var child String
if !s.ReadOptionalASN1(&child, &present, tag) {
return false
}
if outPresent != nil {
*outPresent = present
}
if present {
var oct String
if !child.ReadASN1(&oct, asn1.OCTET_STRING) || !child.Empty() {
return false
}
*out = oct
} else {
*out = nil
}
return true
} | ReadOptionalASN1OctetString attempts to read an optional ASN.1 OCTET STRING
explicitly tagged with tag into out and advances. If no element with a
matching tag is present, it sets "out" to nil instead. It reports
whether the read was successful. | ReadOptionalASN1OctetString | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func (s *String) ReadOptionalASN1Boolean(out *bool, defaultValue bool) bool {
var present bool
var child String
if !s.ReadOptionalASN1(&child, &present, asn1.BOOLEAN) {
return false
}
if !present {
*out = defaultValue
return true
}
return s.ReadASN1Boolean(out)
} | ReadOptionalASN1Boolean sets *out to the value of the next ASN.1 BOOLEAN or,
if the next bytes are not an ASN.1 BOOLEAN, to the value of defaultValue.
It reports whether the operation was successful. | ReadOptionalASN1Boolean | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1.go | BSD-3-Clause |
func NewBuilder(buffer []byte) *Builder {
return &Builder{
result: buffer,
}
} | NewBuilder creates a Builder that appends its output to the given buffer.
Like append(), the slice will be reallocated if its capacity is exceeded.
Use Bytes to get the final buffer. | NewBuilder | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/builder.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/builder.go | BSD-3-Clause |
func NewFixedBuilder(buffer []byte) *Builder {
return &Builder{
result: buffer,
fixedSize: true,
}
} | NewFixedBuilder creates a Builder that appends its output into the given
buffer. This builder does not reallocate the output buffer. Writes that
would exceed the buffer's capacity are treated as an error. | NewFixedBuilder | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/builder.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/builder.go | BSD-3-Clause |
func (b *Builder) SetError(err error) {
b.err = err
} | SetError sets the value to be returned as the error from Bytes. Writes
performed after calling SetError are ignored. | SetError | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/builder.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/builder.go | BSD-3-Clause |
func (b *Builder) Bytes() ([]byte, error) {
if b.err != nil {
return nil, b.err
}
return b.result[b.offset:], nil
} | Bytes returns the bytes written by the builder or an error if one has
occurred during building. | Bytes | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/builder.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/builder.go | BSD-3-Clause |
func (b *Builder) BytesOrPanic() []byte {
if b.err != nil {
panic(b.err)
}
return b.result[b.offset:]
} | BytesOrPanic returns the bytes written by the builder or panics if an error
has occurred during building. | BytesOrPanic | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/builder.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/builder.go | BSD-3-Clause |
func (b *Builder) AddUint8(v uint8) {
b.add(byte(v))
} | AddUint8 appends an 8-bit value to the byte string. | AddUint8 | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/builder.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/builder.go | BSD-3-Clause |
func (b *Builder) AddUint16(v uint16) {
b.add(byte(v>>8), byte(v))
} | AddUint16 appends a big-endian, 16-bit value to the byte string. | AddUint16 | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/builder.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/builder.go | BSD-3-Clause |
func (b *Builder) AddUint24(v uint32) {
b.add(byte(v>>16), byte(v>>8), byte(v))
} | AddUint24 appends a big-endian, 24-bit value to the byte string. The highest
byte of the 32-bit input value is silently truncated. | AddUint24 | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/builder.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/builder.go | BSD-3-Clause |
func (b *Builder) AddUint32(v uint32) {
b.add(byte(v>>24), byte(v>>16), byte(v>>8), byte(v))
} | AddUint32 appends a big-endian, 32-bit value to the byte string. | AddUint32 | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/builder.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/builder.go | BSD-3-Clause |
func (b *Builder) AddBytes(v []byte) {
b.add(v...)
} | AddBytes appends a sequence of bytes to the byte string. | AddBytes | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/builder.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/builder.go | BSD-3-Clause |
func (b *Builder) AddUint8LengthPrefixed(f BuilderContinuation) {
b.addLengthPrefixed(1, false, f)
} | AddUint8LengthPrefixed adds a 8-bit length-prefixed byte sequence. | AddUint8LengthPrefixed | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/builder.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/builder.go | BSD-3-Clause |
func (b *Builder) AddUint16LengthPrefixed(f BuilderContinuation) {
b.addLengthPrefixed(2, false, f)
} | AddUint16LengthPrefixed adds a big-endian, 16-bit length-prefixed byte sequence. | AddUint16LengthPrefixed | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/builder.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/builder.go | BSD-3-Clause |
func (b *Builder) AddUint24LengthPrefixed(f BuilderContinuation) {
b.addLengthPrefixed(3, false, f)
} | AddUint24LengthPrefixed adds a big-endian, 24-bit length-prefixed byte sequence. | AddUint24LengthPrefixed | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/builder.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/builder.go | BSD-3-Clause |
func (b *Builder) AddUint32LengthPrefixed(f BuilderContinuation) {
b.addLengthPrefixed(4, false, f)
} | AddUint32LengthPrefixed adds a big-endian, 32-bit length-prefixed byte sequence. | AddUint32LengthPrefixed | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/builder.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/builder.go | BSD-3-Clause |
func (b *Builder) Unwrite(n int) {
if b.err != nil {
return
}
if b.child != nil {
panic("cryptobyte: attempted unwrite while child is pending")
}
length := len(b.result) - b.pendingLenLen - b.offset
if length < 0 {
panic("cryptobyte: internal error")
}
if n > length {
panic("cryptobyte: attempted to unwrite more than was written")
}
b.result = b.result[:len(b.result)-n]
} | Unwrite rolls back n bytes written directly to the Builder. An attempt by a
child builder passed to a continuation to unwrite bytes from its parent will
panic. | Unwrite | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/builder.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/builder.go | BSD-3-Clause |
func (b *Builder) AddValue(v MarshalingValue) {
err := v.Marshal(b)
if err != nil {
b.err = err
}
} | AddValue calls Marshal on v, passing a pointer to the builder to append to.
If Marshal returns an error, it is set on the Builder so that subsequent
appends don't have an effect. | AddValue | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/builder.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/builder.go | BSD-3-Clause |
func (s *String) read(n int) []byte {
if len(*s) < n {
return nil
}
v := (*s)[:n]
*s = (*s)[n:]
return v
} | read advances a String by n bytes and returns them. If less than n bytes
remain, it returns nil. | read | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/string.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/string.go | BSD-3-Clause |
func (s *String) Skip(n int) bool {
return s.read(n) != nil
} | Skip advances the String by n byte and reports whether it was successful. | Skip | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/string.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/string.go | BSD-3-Clause |
func (s *String) ReadUint8(out *uint8) bool {
v := s.read(1)
if v == nil {
return false
}
*out = uint8(v[0])
return true
} | ReadUint8 decodes an 8-bit value into out and advances over it.
It reports whether the read was successful. | ReadUint8 | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/string.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/string.go | BSD-3-Clause |
func (s *String) ReadUint16(out *uint16) bool {
v := s.read(2)
if v == nil {
return false
}
*out = uint16(v[0])<<8 | uint16(v[1])
return true
} | ReadUint16 decodes a big-endian, 16-bit value into out and advances over it.
It reports whether the read was successful. | ReadUint16 | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/string.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/string.go | BSD-3-Clause |
func (s *String) ReadUint24(out *uint32) bool {
v := s.read(3)
if v == nil {
return false
}
*out = uint32(v[0])<<16 | uint32(v[1])<<8 | uint32(v[2])
return true
} | ReadUint24 decodes a big-endian, 24-bit value into out and advances over it.
It reports whether the read was successful. | ReadUint24 | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/string.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/string.go | BSD-3-Clause |
func (s *String) ReadUint32(out *uint32) bool {
v := s.read(4)
if v == nil {
return false
}
*out = uint32(v[0])<<24 | uint32(v[1])<<16 | uint32(v[2])<<8 | uint32(v[3])
return true
} | ReadUint32 decodes a big-endian, 32-bit value into out and advances over it.
It reports whether the read was successful. | ReadUint32 | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/string.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/string.go | BSD-3-Clause |
func (s *String) ReadUint8LengthPrefixed(out *String) bool {
return s.readLengthPrefixed(1, out)
} | ReadUint8LengthPrefixed reads the content of an 8-bit length-prefixed value
into out and advances over it. It reports whether the read was successful. | ReadUint8LengthPrefixed | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/string.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/string.go | BSD-3-Clause |
func (s *String) ReadUint16LengthPrefixed(out *String) bool {
return s.readLengthPrefixed(2, out)
} | ReadUint16LengthPrefixed reads the content of a big-endian, 16-bit
length-prefixed value into out and advances over it. It reports whether the
read was successful. | ReadUint16LengthPrefixed | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/string.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/string.go | BSD-3-Clause |
func (s *String) ReadUint24LengthPrefixed(out *String) bool {
return s.readLengthPrefixed(3, out)
} | ReadUint24LengthPrefixed reads the content of a big-endian, 24-bit
length-prefixed value into out and advances over it. It reports whether
the read was successful. | ReadUint24LengthPrefixed | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/string.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/string.go | BSD-3-Clause |
func (s *String) ReadBytes(out *[]byte, n int) bool {
v := s.read(n)
if v == nil {
return false
}
*out = v
return true
} | ReadBytes reads n bytes into out and advances over them. It reports
whether the read was successful. | ReadBytes | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/string.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/string.go | BSD-3-Clause |
func (s *String) CopyBytes(out []byte) bool {
n := len(out)
v := s.read(n)
if v == nil {
return false
}
return copy(out, v) == n
} | CopyBytes copies len(out) bytes into out and advances over them. It reports
whether the copy operation was successful | CopyBytes | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/string.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/string.go | BSD-3-Clause |
func (s String) Empty() bool {
return len(s) == 0
} | Empty reports whether the string does not contain any bytes. | Empty | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/string.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/string.go | BSD-3-Clause |
func (t Tag) Constructed() Tag { return t | classConstructed } | Constructed returns t with the constructed class bit set. | Constructed | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1/asn1.go | BSD-3-Clause |
func (t Tag) ContextSpecific() Tag { return t | classContextSpecific } | ContextSpecific returns t with the context-specific class bit set. | ContextSpecific | go | flynn/flynn | vendor/golang.org/x/crypto/cryptobyte/asn1/asn1.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/crypto/cryptobyte/asn1/asn1.go | BSD-3-Clause |
func RegisterBrokenAuthHeaderProvider(tokenURL string) {} | RegisterBrokenAuthHeaderProvider previously did something. It is now a no-op.
Deprecated: this function no longer does anything. Caller code that
wants to avoid potential extra HTTP requests made during
auto-probing of the provider's auth style should set
Endpoint.AuthStyle. | RegisterBrokenAuthHeaderProvider | go | flynn/flynn | vendor/golang.org/x/oauth2/oauth2.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/oauth2.go | BSD-3-Clause |
func SetAuthURLParam(key, value string) AuthCodeOption {
return setParam{key, value}
} | SetAuthURLParam builds an AuthCodeOption which passes key/value parameters
to a provider's authorization endpoint. | SetAuthURLParam | go | flynn/flynn | vendor/golang.org/x/oauth2/oauth2.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/oauth2.go | BSD-3-Clause |
func (c *Config) AuthCodeURL(state string, opts ...AuthCodeOption) string {
var buf bytes.Buffer
buf.WriteString(c.Endpoint.AuthURL)
v := url.Values{
"response_type": {"code"},
"client_id": {c.ClientID},
}
if c.RedirectURL != "" {
v.Set("redirect_uri", c.RedirectURL)
}
if len(c.Scopes) > 0 {
v.Set("scope", strings.Join(c.Scopes, " "))
}
if state != "" {
// TODO(light): Docs say never to omit state; don't allow empty.
v.Set("state", state)
}
for _, opt := range opts {
opt.setValue(v)
}
if strings.Contains(c.Endpoint.AuthURL, "?") {
buf.WriteByte('&')
} else {
buf.WriteByte('?')
}
buf.WriteString(v.Encode())
return buf.String()
} | AuthCodeURL returns a URL to OAuth 2.0 provider's consent page
that asks for permissions for the required scopes explicitly.
State is a token to protect the user from CSRF attacks. You must
always provide a non-empty string and validate that it matches the
the state query parameter on your redirect callback.
See http://tools.ietf.org/html/rfc6749#section-10.12 for more info.
Opts may include AccessTypeOnline or AccessTypeOffline, as well
as ApprovalForce.
It can also be used to pass the PKCE challenge.
See https://www.oauth.com/oauth2-servers/pkce/ for more info. | AuthCodeURL | go | flynn/flynn | vendor/golang.org/x/oauth2/oauth2.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/oauth2.go | BSD-3-Clause |
func (c *Config) PasswordCredentialsToken(ctx context.Context, username, password string) (*Token, error) {
v := url.Values{
"grant_type": {"password"},
"username": {username},
"password": {password},
}
if len(c.Scopes) > 0 {
v.Set("scope", strings.Join(c.Scopes, " "))
}
return retrieveToken(ctx, c, v)
} | PasswordCredentialsToken converts a resource owner username and password
pair into a token.
Per the RFC, this grant type should only be used "when there is a high
degree of trust between the resource owner and the client (e.g., the client
is part of the device operating system or a highly privileged application),
and when other authorization grant types are not available."
See https://tools.ietf.org/html/rfc6749#section-4.3 for more info.
The provided context optionally controls which HTTP client is used. See the HTTPClient variable. | PasswordCredentialsToken | go | flynn/flynn | vendor/golang.org/x/oauth2/oauth2.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/oauth2.go | BSD-3-Clause |
func (c *Config) Exchange(ctx context.Context, code string, opts ...AuthCodeOption) (*Token, error) {
v := url.Values{
"grant_type": {"authorization_code"},
"code": {code},
}
if c.RedirectURL != "" {
v.Set("redirect_uri", c.RedirectURL)
}
for _, opt := range opts {
opt.setValue(v)
}
return retrieveToken(ctx, c, v)
} | Exchange converts an authorization code into a token.
It is used after a resource provider redirects the user back
to the Redirect URI (the URL obtained from AuthCodeURL).
The provided context optionally controls which HTTP client is used. See the HTTPClient variable.
The code will be in the *http.Request.FormValue("code"). Before
calling Exchange, be sure to validate FormValue("state").
Opts may include the PKCE verifier code if previously used in AuthCodeURL.
See https://www.oauth.com/oauth2-servers/pkce/ for more info. | Exchange | go | flynn/flynn | vendor/golang.org/x/oauth2/oauth2.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/oauth2.go | BSD-3-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.