// Decode decrypts, authenticates and deserializes cookie's session data.
493437
func (s *Session) Decode(data []byte) error {
	if len(data) == 0 {
		return nil
	}

	box := make([]byte, base64.RawStdEncoding.DecodedLen(len(data)))
	if _, err := base64.RawStdEncoding.Decode(box, data); err != nil {
		return errors.Wrapf(err, "failed decoding session data")
	}

	var nonce [24]byte
	var msg []byte
	var key [32]byte
	var ok bool
	copy(nonce[:], box[:24])

	for _, k := range s.keys {
		copy(key[:], k)
		msg, ok = secretbox.Open(nil, box[24:], &nonce, &key)
		if ok {
			if err := msgpack.Unmarshal(msg, &s.data); err != nil {
				return errors.Wrapf(err, "failed decoding session data")
			}
			return nil
		}
	}

	return errors.New("failed decrypting session data")
}
748446
func (c *CookieOverseer) encode(plaintext string) (string, error) {
	nonce := make([]byte, c.gcmBlockMode.NonceSize())
	if _, err := rand.Read(nonce); err != nil {
		return "", errors.Wrap(err, "failed to encode session cookie value")
	}

	// Append ciphertext to the end of nonce so we have the nonce for decrypt
	ciphertext := c.gcmBlockMode.Seal(nonce, nonce, []byte(plaintext), nil)
	return base64.StdEncoding.EncodeToString(ciphertext), nil
}
33662
func Decode(v string) *User {
	values, err := url.ParseQuery(v)
	if err != nil {
		return nil
	}

	attrs := map[string]string{}
	for key, _ := range values {
		attrs[key]=values.Get(key)
	}

	return &User {
		Id    : values.Get("id"),
		Name  : values.Get("name"),
		Email : values.Get("email"),
		Photo : values.Get("photo"),
		Attrs : attrs,
	}
}
996763
func (pder *CookieProvider) SessionRead(sid string) (Store, error) {
	maps, _ := decodeCookie(pder.block,
		pder.config.SecurityKey,
		pder.config.SecurityName,
		sid, pder.maxlifetime)
	if maps == nil {
		maps = make(map[interface{}]interface{})
	}
	rs := &CookieSessionStore{sid: sid, values: maps}
	return rs, nil
}
780875
func (s SecureJsonData) Decrypt() map[string]string {
	decrypted := make(map[string]string)
	for key, data := range s {
		decryptedData, err := util.Decrypt(data, setting.SecretKey)
		if err != nil {
			log.Fatal(4, err.Error())
		}

		decrypted[key] = string(decryptedData)
	}
	return decrypted
}
833439
func (userdata VirtualMachineUserData) Decode() (string, error) {
	data, err := base64.StdEncoding.DecodeString(userdata.UserData)
	if err != nil {
		return "", err
	}
	// 0x1f8b is the magic number for gzip
	if len(data) < 2 || data[0] != 0x1f || data[1] != 0x8b {
		return string(data), nil
	}
	gr, err := gzip.NewReader(bytes.NewBuffer(data))
	if err != nil {
		return "", err
	}
	defer gr.Close() // nolint: errcheck

	str, err := ioutil.ReadAll(gr)
	if err != nil {
		return "", err
	}
	return string(str), nil
}
410123
func Decrypt(data []byte, key []byte) []byte {
	if data == nil || len(data) == 0 {
		return data
	}
	return toBytes(decrypt(toUint32s(data, false), toUint32s(key, false)), true)
}
8326
func Decode(src []byte, mode int) (inst Inst, err error) {
	return decode1(src, mode, false)
}
1095282
func (d *Decoder) Decode(db *Database) error {
	// Read header
	db.Header = new(DBHeader)
	if err := db.Header.readFrom(d.r); err != nil {
		return err
	}

	// Calculate transformed key to decrypt and calculate HMAC
	transformedKey, err := db.getTransformedKey()
	if err != nil {
		return err
	}

	// Read hashes and validate them (Kdbx v4)
	if db.Header.IsKdbx4() {
		db.Hashes = new(DBHashes)
		if err := db.Hashes.readFrom(d.r); err != nil {
			return err
		}

		if db.Options.ValidateHashes {
			if err := db.Header.ValidateSha256(db.Hashes.Sha256); err != nil {
				return err
			}

			hmacKey := buildHmacKey(db, transformedKey)
			if err := db.Header.ValidateHmacSha256(hmacKey, db.Hashes.Hmac); err != nil {
				return errors.New("Wrong password? HMAC-SHA256 of header mismatching")
			}
		}
	}

	// Decode raw content
	rawContent, _ := ioutil.ReadAll(d.r)
	if err := decodeRawContent(db, rawContent, transformedKey); err != nil {
		return err
	}

	contentReader := bytes.NewReader(db.Content.RawData)

	// Read InnerHeader (Kdbx v4)
	if db.Header.IsKdbx4() {
		db.Content.InnerHeader = new(InnerHeader)
		if err := db.Content.InnerHeader.readFrom(contentReader); err != nil {
			return err
		}
	}

	// Decode xml
	xmlDecoder := xml.NewDecoder(contentReader)
	return xmlDecoder.Decode(db.Content)
}
991864
func (p *ProviderData) SessionFromCookie(v string, c *cookie.Cipher) (s *SessionState, err error) {
	return DecodeSessionState(v, c)
}
1285095
func DecodeSession(b []byte, s Session) (Session, error) {
	var (
		line Line
		err  error
	)
	scanner := newScanner(b)
	for scanner.Scan() {
		// trying to reuse some memory
		l := len(s)
		if cap(s) > l+1 {
			// picking element from s that is not in
			// slice bounds, but in underlying array
			// and reusing it byte slice
			line.Value = s[:l+1][l].Value[:0]
		}
		if err = line.Decode(scanner.Line()); err != nil {
			break
		}
		s = append(s, line)
		line.Value = nil // not corrupting.
	}
	return s, err
}
874158
func Decode(token string) (Token, error) {
	var t Token
	err := (&t).UnmarshalText([]byte(token))
	return t, err
}
174766
func (handle *ContextHandle) Decrypt(session mPkcs11.SessionHandle, cypher []byte) ([]byte, error) {

	handle.lock.RLock()
	defer handle.lock.RUnlock()

	return handle.ctx.Decrypt(session, cypher)
}
903339
func decode(token string) ([]byte, error) {
	decoded, err := hex.DecodeString(token)
	if err != nil {
		return nil, trace.Wrap(err)
	}

	if len(decoded) != tokenLenBytes {
		return nil, trace.BadParameter("invalid CSRF token byte length, expected %v, got %v", tokenLenBytes, len(decoded))
	}

	return decoded, nil
}
307157
func (sk *SecretKey) Decrypt(in []byte) ([]byte, error) {
	return sk.Key.Decrypt(in)
}
40824
func decode(encryptedB64 string) (stellar1.EncryptedAccountBundle, stellar1.Hash, error) {
	cipherpack, err := base64.StdEncoding.DecodeString(encryptedB64)
	if err != nil {
		return stellar1.EncryptedAccountBundle{}, stellar1.Hash{}, err
	}
	encHash := sha256.Sum256(cipherpack)
	var enc stellar1.EncryptedAccountBundle
	if err = libkb.MsgpackDecode(&enc, cipherpack); err != nil {
		return stellar1.EncryptedAccountBundle{}, stellar1.Hash{}, err
	}
	return enc, encHash[:], nil
}
464965
func (g *CookieGenerator) DecodeToken(encrypted []byte) (*Cookie, error) {
	// if the client didn't send any Cookie, DecodeToken will be called with a nil-slice
	if len(encrypted) == 0 {
		return nil, nil
	}

	data, err := g.cookieProtector.DecodeToken(encrypted)
	if err != nil {
		return nil, err
	}
	t := &token{}
	rest, err := asn1.Unmarshal(data, t)
	if err != nil {
		return nil, err
	}
	if len(rest) != 0 {
		return nil, fmt.Errorf("rest when unpacking token: %d", len(rest))
	}
	cookie := &Cookie{
		RemoteAddr: decodeRemoteAddr(t.RemoteAddr),
		SentTime:   time.Unix(t.Timestamp, 0),
	}
	if len(t.OriginalDestConnectionID) > 0 {
		cookie.OriginalDestConnectionID = protocol.ConnectionID(t.OriginalDestConnectionID)
	}
	return cookie, nil
}