MCPcopy Create free account
hub / github.com/docker/cli / decodeAuth

Function decodeAuth

cli/config/configfile/file.go:297–317  ·  view source on GitHub ↗

decodeAuth decodes a base64 encoded string and returns username and password

(authStr string)

Source from the content-addressed store, hash-verified

295
296// decodeAuth decodes a base64 encoded string and returns username and password
297func decodeAuth(authStr string) (string, string, error) {
298 if authStr == "" {
299 return "", "", nil
300 }
301
302 decLen := base64.StdEncoding.DecodedLen(len(authStr))
303 decoded := make([]byte, decLen)
304 authByte := []byte(authStr)
305 n, err := base64.StdEncoding.Decode(decoded, authByte)
306 if err != nil {
307 return "", "", err
308 }
309 if n > decLen {
310 return "", "", errors.New("something went wrong decoding auth config")
311 }
312 userName, password, ok := strings.Cut(string(decoded), ":")
313 if !ok || userName == "" {
314 return "", "", errors.New("invalid auth configuration file")
315 }
316 return userName, strings.Trim(password, "\x00"), nil
317}
318
319// GetCredentialsStore returns a new credentials store from the settings in the
320// configuration file

Callers 3

TestEncodeAuthFunction · 0.85
LoadFromReaderMethod · 0.85
parseEnvConfigFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestEncodeAuthFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…