...

Source file src/github.com/docker/distribution/registry/auth/token/util.go

Documentation: github.com/docker/distribution/registry/auth/token

     1  package token
     2  
     3  import (
     4  	"encoding/base64"
     5  	"errors"
     6  	"strings"
     7  )
     8  
     9  // joseBase64UrlEncode encodes the given data using the standard base64 url
    10  // encoding format but with all trailing '=' characters omitted in accordance
    11  // with the jose specification.
    12  // http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-31#section-2
    13  func joseBase64UrlEncode(b []byte) string {
    14  	return strings.TrimRight(base64.URLEncoding.EncodeToString(b), "=")
    15  }
    16  
    17  // joseBase64UrlDecode decodes the given string using the standard base64 url
    18  // decoder but first adds the appropriate number of trailing '=' characters in
    19  // accordance with the jose specification.
    20  // http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-31#section-2
    21  func joseBase64UrlDecode(s string) ([]byte, error) {
    22  	switch len(s) % 4 {
    23  	case 0:
    24  	case 2:
    25  		s += "=="
    26  	case 3:
    27  		s += "="
    28  	default:
    29  		return nil, errors.New("illegal base64url string")
    30  	}
    31  	return base64.URLEncoding.DecodeString(s)
    32  }
    33  
    34  // actionSet is a special type of stringSet.
    35  type actionSet struct {
    36  	stringSet
    37  }
    38  
    39  func newActionSet(actions ...string) actionSet {
    40  	return actionSet{newStringSet(actions...)}
    41  }
    42  
    43  // Contains calls StringSet.Contains() for
    44  // either "*" or the given action string.
    45  func (s actionSet) contains(action string) bool {
    46  	return s.stringSet.contains("*") || s.stringSet.contains(action)
    47  }
    48  
    49  // contains returns true if q is found in ss.
    50  func contains(ss []string, q string) bool {
    51  	for _, s := range ss {
    52  		if s == q {
    53  			return true
    54  		}
    55  	}
    56  
    57  	return false
    58  }
    59  

View as plain text