// NewExtensionWithKey creates the payload of a Chrome extension file which is
// signed by the provided private key.
195199
func NewExtensionWithKey(basePath string, key *rsa.PrivateKey) ([]byte, error) {
	zip, err := zip.New(basePath)
	if err != nil {
		return nil, err
	}

	h := sha1.New()
	if _, err := io.Copy(h, bytes.NewReader(zip.Bytes())); err != nil {
		return nil, err
	}
	hashed := h.Sum(nil)

	signature, err := rsa.SignPKCS1v15(rand.Reader, key, crypto.SHA1, hashed[:])
	if err != nil {
		return nil, err
	}

	pubKey, err := x509.MarshalPKIXPublicKey(key.Public())
	if err != nil {
		return nil, err
	}

	// This format is documented at https://developer.chrome.com/extensions/crx .
	buf := new(bytes.Buffer)
	if _, err := buf.Write([]byte("Cr24")); err != nil { // Magic number.
		return nil, err
	}

	// Version.
	if err := binary.Write(buf, binary.LittleEndian, uint32(2)); err != nil {
		return nil, err
	}

	// Public key length.
	if err := binary.Write(buf, binary.LittleEndian, uint32(len(pubKey))); err != nil {
		return nil, err
	}
	// Signature length.
	if err := binary.Write(buf, binary.LittleEndian, uint32(len(signature))); err != nil {
		return nil, err
	}

	// Public key payload.
	if err := binary.Write(buf, binary.LittleEndian, pubKey); err != nil {
		return nil, err
	}

	// Signature payload.
	if err := binary.Write(buf, binary.LittleEndian, signature); err != nil {
		return nil, err
	}

	// Zipped extension directory payload.
	if err := binary.Write(buf, binary.LittleEndian, zip.Bytes()); err != nil {
		return nil, err
	}

	return buf.Bytes(), nil
}
843769
func (builder *FetchPreflistCommandBuilder) WithKey(key string) *FetchPreflistCommandBuilder {
	builder.protobuf.Key = []byte(key)
	return builder
}
1288794
func (s *Service) SignRequestWithKey(r *http.Request, secretKey []byte) error {
	// extract request body bytes
	bodyBytes, err := readBody(r)
	if err != nil {
		return err
	}

	// extract any headers if requested
	headerValues, err := extractHeaderValues(r, s.config.HeadersToSign)
	if err != nil {
		return err
	}

	// get 128-bit random number from /dev/urandom and base16 encode it
	nonce, err := s.randomProvider.HexDigest(16)
	if err != nil {
		return fmt.Errorf("unable to get random : %v", err)
	}

	// get current timestamp
	timestamp := strconv.FormatInt(s.timeProvider.UtcNow().Unix(), 10)

	// compute the hmac and base16 encode it
	computedMAC := computeMAC(secretKey, s.config.SignVerbAndURI, r.Method, r.URL.RequestURI(),
		timestamp, nonce, bodyBytes, headerValues)
	signature := hex.EncodeToString(computedMAC)

	// set headers
	r.Header.Set(s.config.NonceHeaderName, nonce)
	r.Header.Set(s.config.TimestampHeaderName, timestamp)
	r.Header.Set(s.config.SignatureHeaderName, signature)
	r.Header.Set(s.config.SignatureVersionHeaderName, "2")

	// set the body bytes we read in to nil to hint to the gc to pick it up
	bodyBytes = nil

	return nil
}
972575
func (oms *OnlyMapperStruct) NewKey() sophie.Sophier {
	if oms.NewKeyF != nil {
		return oms.NewKeyF()
	}
	// sophie.RawByteSlice is a Sophier that can read any Sophie data.
	return new(sophie.RawByteSlice)
}
1301449
func NewECPublicKey(b []byte) *ECPublicKey {
	ensureKeyLength(b)
	k := &ECPublicKey{}
	copy(k.key[:], b)
	return k
}
1320986
func NewWithKey(server, accessKey string) *Account {
	return New(server).WithAuth(auth.AccessKey(accessKey))
}
628190
func (builder *UpdateGSetCommandBuilder) WithKey(key string) *UpdateGSetCommandBuilder {
	builder.protobuf.Key = []byte(key)
	return builder
}
910578
func NewKey(ip net.IP, mask net.IPMask) Key {
	result := Key{}

	ones, _ := mask.Size()
	if ip4 := ip.To4(); ip4 != nil {
		if mask == nil {
			ones = net.IPv4len * 8
		}
		result.Prefixlen = getPrefixLen(ones)
		result.Family = bpf.EndpointKeyIPv4
		copy(result.IP[:], ip4)
	} else {
		if mask == nil {
			ones = net.IPv6len * 8
		}
		result.Prefixlen = getPrefixLen(ones)
		result.Family = bpf.EndpointKeyIPv6
		copy(result.IP[:], ip)
	}

	return result
}
269683
func NewPbkdf2Key(password []byte, size int) Key {
	return pbkdf2Key{password: password, size: size}
}
1324440
func (b *BigIP) AddKey(config *Key) error {
	return b.post(config, uriSys, uriFile, uriSslKey)
}
89077
func NewKeyValueExpr(k, v Expr, pos Pos) *KeyValueExpr {
	return &KeyValueExpr{pos, k, v}
}
913217
func (builder *FetchValueCommandBuilder) WithKey(key string) *FetchValueCommandBuilder {
	builder.protobuf.Key = []byte(key)
	return builder
}
204447
func TokenProviderWithKey(keyName, key string) TokenProviderOption {
	return func(provider *TokenProvider) error {
		provider.signer = NewSigner(keyName, key)
		return nil
	}
}
862177
func newExtensionHandler(params []byte, pers protocol.Perspective) tlsExtensionHandler {
	return &extensionHandler{
		ourParams:   params,
		paramsChan:  make(chan []byte),
		perspective: pers,
	}
}
1316947
func NewAuthKey(KEY [32]uint8) *AuthKey {
	m := AuthKey{}
	m.KEY = KEY
	return &m
}
253962
func (a *LocalKeyAgent) AddKey(key *Key) (*agent.AddedKey, error) {
	// save it to disk (usually into ~/.tsh)
	err := a.keyStore.AddKey(a.proxyHost, a.username, key)
	if err != nil {
		return nil, trace.Wrap(err)
	}

	// load key into the teleport agent and system agent
	return a.LoadKey(*key)
}
508495
func (p *ResponsePath) WithKey(key interface{}) *ResponsePath {
	return &ResponsePath{
		Prev: p,
		Key:  key,
	}
}