// Decode an encrypted stream that start with an IV.
971982
func (a *AES) Decode(r io.Reader, w io.Writer) error {
	iv := make([]byte, aes.BlockSize)

	block, err := aes.NewCipher(a.Key)
	if err != nil {
		return err
	} else if _, err = r.Read(iv[:]); err != nil {
		return err
	}
	stream := cipher.NewCFBDecrypter(block, iv)
	reader := &cipher.StreamReader{S: stream, R: r}
	_, err = io.Copy(w, reader)
	return err
}
260572
func (e *Encoding) Decode(dst, src []byte) (int, error) {
	if len(src)%2 == 1 {
		return 0, ErrLength
	}

	for i := 0; i < len(src)/2; i++ {
		a, ok := e.fromHexChar(src[i*2])
		if !ok {
			return 0, InvalidByteError(src[i*2])
		}
		b, ok := e.fromHexChar(src[i*2+1])
		if !ok {
			return 0, InvalidByteError(src[i*2+1])
		}
		dst[i] = (a << 4) | b
	}

	return len(src) / 2, nil
}
19968
func Decode(r io.Reader, password []byte) (KeyStore, error) {
	ksd := keyStoreDecoder{
		r:  r,
		md: sha1.New(),
	}
	passwordBytes := passwordBytes(password)
	defer zeroing(passwordBytes)
	_, err := ksd.md.Write(passwordBytes)
	if err != nil {
		return nil, err
	}
	_, err = ksd.md.Write(whitenerMessage)
	if err != nil {
		return nil, err
	}

	readMagic, err := ksd.readUint32()
	if err != nil {
		return nil, err
	}
	if readMagic != magic {
		return nil, ErrIncorrectMagic
	}
	version, err := ksd.readUint32()
	if err != nil {
		return nil, err
	}
	count, err := ksd.readUint32()
	if err != nil {
		return nil, err
	}
	keyStore := KeyStore{}
	for entitiesCount := count; entitiesCount > 0; entitiesCount-- {
		alias, entry, err := ksd.readEntry(version, password)
		if err != nil {
			return nil, err
		}
		keyStore[alias] = entry
	}

	computedDigest := ksd.md.Sum(nil)
	actualDigest, err := ksd.readBytes(uint32(ksd.md.Size()))
	for i := 0; i < len(actualDigest); i++ {
		if actualDigest[i] != computedDigest[i] {
			return nil, ErrInvalidDigest
		}
	}

	return keyStore, nil
}
1139499
func (dec *Decoder) DecodeInt8(v *int8) error {
	if dec.isPooled == 1 {
		panic(InvalidUsagePooledDecoderError("Invalid usage of pooled decoder"))
	}
	return dec.decodeInt8(v)
}
1066126
func Decode(source Expr, kvs ...Expr) Expr {
	d := &decode{Source: source}
	for i := 0; i < len(kvs); i += 2 {
		k := kvs[i]
		if i+1 < len(kvs) {
			v := kvs[i+1]
			d.Keys = append(d.Keys, k)
			d.Values = append(d.Values, v)
		} else {
			d.Default = k
		}
	}
	return d
}
386658
func (a *ChannelUpdate) Decode(r io.Reader, pver uint32) error {
	err := ReadElements(r,
		&a.Signature,
		a.ChainHash[:],
		&a.ShortChannelID,
		&a.Timestamp,
		&a.MessageFlags,
		&a.ChannelFlags,
		&a.TimeLockDelta,
		&a.HtlcMinimumMsat,
		&a.BaseFee,
		&a.FeeRate,
	)
	if err != nil {
		return err
	}

	// Now check whether the max HTLC field is present and read it if so.
	if a.MessageFlags.HasMaxHtlc() {
		if err := ReadElements(r, &a.HtlcMaximumMsat); err != nil {
			return err
		}
	}

	// Now that we've read out all the fields that we explicitly know of,
	// we'll collect the remainder into the ExtraOpaqueData field. If there
	// aren't any bytes, then we'll snip off the slice to avoid carrying
	// around excess capacity.
	a.ExtraOpaqueData, err = ioutil.ReadAll(r)
	if err != nil {
		return err
	}
	if len(a.ExtraOpaqueData) == 0 {
		a.ExtraOpaqueData = nil
	}

	return nil
}
499924
func (c *RevokeAndAck) Decode(r io.Reader, pver uint32) error {
	return ReadElements(r,
		&c.ChanID,
		c.Revocation[:],
		&c.NextRevocationKey,
	)
}
757428
func Decode(src convert.ReadSeekCloser, sr int) (*Stream, error) {
	decoded, channelNum, sampleRate, err := decode(src)
	if err != nil {
		return nil, err
	}
	if channelNum != 1 && channelNum != 2 {
		return nil, fmt.Errorf("vorbis: number of channels must be 1 or 2 but was %d", channelNum)
	}
	var s convert.ReadSeekCloser = decoded
	size := decoded.Length()
	if channelNum == 1 {
		s = convert.NewStereo16(s, true, false)
		size *= 2
	}
	if sampleRate != sr {
		r := convert.NewResampling(s, size, sampleRate, sr)
		s = r
		size = r.Length()
	}
	return &Stream{decoded: s, size: size}, nil
}
456034
func (c *ClosingSigned) Decode(r io.Reader, pver uint32) error {
	return ReadElements(r, &c.ChannelID, &c.FeeSatoshis, &c.Signature)
}
796170
func (i *ID) Decode(b []byte) error {
	if len(b) != IDLength {
		return ErrInvalidIDLength
	}

	res, err := strconv.ParseUint(unsafeBytesToString(b), 16, 64)
	if err != nil {
		return err
	}

	if *i = ID(res); !i.Valid() {
		return ErrInvalidID
	}
	return nil
}
208110
func Decrypt(payload []byte, secret string) ([]byte, error) {
	salt := payload[:saltLength]
	key := encryptionKeyToBytes(secret, string(salt))

	block, err := aes.NewCipher(key)
	if err != nil {
		return nil, err
	}

	// The IV needs to be unique, but not secure. Therefore it's common to
	// include it at the beginning of the ciphertext.
	if len(payload) < aes.BlockSize {
		return nil, errors.New("payload too short")
	}
	iv := payload[saltLength : saltLength+aes.BlockSize]
	payload = payload[saltLength+aes.BlockSize:]
	payloadDst := make([]byte, len(payload))

	stream := cipher.NewCFBDecrypter(block, iv)

	// XORKeyStream can work in-place if the two arguments are the same.
	stream.XORKeyStream(payloadDst, payload)
	return payloadDst, nil
}
55957
func Decode(out interface{}, in string) error {
	obj, err := Parse(in)
	if err != nil {
		return err
	}

	return DecodeObject(out, obj)
}
1353587
func (d Decoder) Decode() (interface{}, error) {
	data, err := d.read()
	if err != nil {
		return nil, err
	}

	return d.decode(data)
}
86198
func (d *Decoder) Decode(data []byte, v interface{}) error {
	f, ok := v.(unmarshalFaster)
	if ok {
		if d.fs == nil {
			d.fs = fflib.NewFFLexer(data)
		} else {
			d.fs.Reset(data)
		}
		return f.UnmarshalJSONFFLexer(d.fs, fflib.FFParse_map_start)
	}

	um, ok := v.(json.Unmarshaler)
	if ok {
		return um.UnmarshalJSON(data)
	}
	return json.Unmarshal(data, v)
}
1319591
func Decode(in string) ([]byte, error) {
	o, err := b64.StdEncoding.DecodeString(in)
	if err != nil {
		// maybe it's in the URL variant?
		o, err = b64.URLEncoding.DecodeString(in)
		if err != nil {
			// ok, just give up...
			return nil, err
		}
	}
	return o, nil
}
787919
func DecodeBytes(b []byte, val interface{}) error {
	r := bytes.NewReader(b)

	stream := streamPool.Get().(*Stream)
	defer streamPool.Put(stream)

	stream.Reset(r, uint64(len(b)))
	if err := stream.Decode(val); err != nil {
		return err
	}
	if r.Len() > 0 {
		return ErrMoreThanOneValue
	}
	return nil
}
414329
func Decode(m interface{}, rawVal interface{}) error {
	config := &DecoderConfig{
		Metadata: nil,
		Result:   rawVal,
	}

	decoder, err := NewDecoder(config)
	if err != nil {
		return err
	}

	return decoder.Decode(m)
}