// Address generates the address trits from the given digests.
// Optionally takes the SpongeFunction to use. Default is Kerl.
323963
func Address(digests Trits, spongeFunc ...SpongeFunction) (Trits, error) {
	h := GetSpongeFunc(spongeFunc, kerl.NewKerl)
	defer h.Reset()

	if err := h.Absorb(digests); err != nil {
		return nil, err
	}
	return h.Squeeze(HashTrinarySize)
}
654756
func (c Config) Address() string {
	return fmt.Sprintf("%s:%d", c.Domain, c.Port)
}
972778
func (n *NIC) Addresses() []tcpip.ProtocolAddress {
	n.mu.RLock()
	defer n.mu.RUnlock()
	addrs := make([]tcpip.ProtocolAddress, 0, len(n.endpoints))
	for nid, ep := range n.endpoints {
		addrs = append(addrs, tcpip.ProtocolAddress{
			Protocol: ep.protocol,
			Address:  nid.LocalAddress,
		})
	}
	return addrs
}
533579
func Address(addr string) Option {
	return func(o *Options) {
		o.Server.Init(server.Address(addr))
	}
}
591832
func NewAddressFromHex(hex string) (address *Address, _ error) {
	a := new(Address)
	if err := a.SetHex(hex); err != nil {
		return nil, err
	}
	return a, nil
}
814367
func (k *Kerl) Absorb(in Trits) error {
	if len(in) == 0 || len(in)%HashTrinarySize != 0 {
		return errors.Wrap(ErrInvalidTritsLength, "trits slice length must be a multiple of 243")
	}

	for i := 1; i <= len(in)/HashTrinarySize; i++ {
		// in[(HashSize*i)-1] = 0
		b, err := KerlTritsToBytes(in[HashTrinarySize*(i-1) : HashTrinarySize*i])
		if err != nil {
			return err
		}
		if _, err := k.s.Write(b); err != nil {
			return err
		}
	}

	return nil
}
340851
func (inst *environInstance) Addresses(ctx context.ProviderCallContext) ([]network.Address, error) {
	if inst.base.Guest == nil {
		return nil, nil
	}
	res := make([]network.Address, 0, len(inst.base.Guest.Net))
	for _, net := range inst.base.Guest.Net {
		for _, ip := range net.IpAddress {
			res = append(res, network.NewAddress(ip))
		}
	}
	return res, nil
}
345436
func Digest(bundleHash []int8, signatureFragment Trits, startOffset int, spongeFunc ...SpongeFunction) (Trits, error) {
	sigLength := len(signatureFragment)

	secLvl, err := GetSecurityLevel(bundleHash)
	if err != nil {
		return nil, err
	}

	sigFrag := make(Trits, sigLength)
	copy(sigFrag, signatureFragment[:sigLength])

	h := GetSpongeFunc(spongeFunc, kerl.NewKerl)
	defer h.Reset()

	dig := make(Trits, HashTrinarySize)
	sig := make(Trits, HashTrinarySize)

	i := startOffset % int(secLvl)
	for digLength := 0; digLength < sigLength; {
		for j := i * ISSChunkLength; j < (i+1)*ISSChunkLength && digLength < sigLength; j += TrinaryRadix {
			copy(sig, sigFrag[digLength:digLength+HashTrinarySize])

			to := (bundleHash[j] + bundleHash[j+1]*3 + bundleHash[j+2]*9) - MinTryteValue

			for k := 0; k < int(to); k++ {
				err := h.Absorb(sig)
				if err != nil {
					return nil, err
				}
				sig, err = h.Squeeze(HashTrinarySize)
				if err != nil {
					return nil, err
				}
				h.Reset()
			}

			copy(sigFrag[digLength:], sig)
			digLength += HashTrinarySize
		}

		i = (i + 1) % int(secLvl)
	}

	err = h.Absorb(sigFrag)
	if err != nil {
		return nil, err
	}

	dig, err = h.Squeeze(HashTrinarySize)
	if err != nil {
		return nil, err
	}

	return dig, nil
}
63364
func (m *Mirror) Address() string {
	m.readAddress()
	return HandleMirrorCredentials(m.address, false)
}
560840
func (a Address) Locality() string {
	var locality string

	if a.City != "" {
		locality = a.City
	} else if a.Town != "" {
		locality = a.Town
	} else if a.Village != "" {
		locality = a.Village
	}

	return locality
}
1140287
func BytesToAddress(b []byte) Address {
	var a Address
	a.SetBytes(b)
	return a
}
1021321
func AddressFromBytes(bs []byte) (address Address, err error) {
	if len(bs) != binary.Word160Length {
		err = fmt.Errorf("slice passed as address '%X' has %d bytes but should have %d bytes",
			bs, len(bs), binary.Word160Length)
		// It is caller's responsibility to check for errors. If they ignore the error we'll assume they want the
		// best-effort mapping of the bytes passed to an address so we don't return here
	}
	copy(address[:], bs)
	return
}
936986
func AddressCount(network *net.IPNet) uint64 {
	prefixLen, bits := network.Mask.Size()
	return 1 << (uint64(bits) - uint64(prefixLen))
}
819612
func (addr *Address) Format() []interface{} {
	fields := make([]interface{}, 4)

	if addr.PersonalName != "" {
		fields[0] = encodeHeader(addr.PersonalName)
	}
	if addr.AtDomainList != "" {
		fields[1] = addr.AtDomainList
	}
	if addr.MailboxName != "" {
		fields[2] = addr.MailboxName
	}
	if addr.HostName != "" {
		fields[3] = addr.HostName
	}

	return fields
}
638602
func (m *Multisig) ValidateAddress(addr Trytes, digests []Trytes, spongeFunc ...SpongeFunction) (bool, error) {
	h := GetSpongeFunc(spongeFunc, kerl.NewKerl)

	for i := range digests {
		digestTrits, err := TrytesToTrits(digests[i])
		if err != nil {
			return false, err
		}
		if err := h.Absorb(digestTrits); err != nil {
			return false, err
		}
	}

	addressTrits, err := h.Squeeze(HashTrinarySize)
	if err != nil {
		return false, err
	}
	return MustTritsToTrytes(addressTrits) == addr, nil
}
1117133
func (a Address) Hex() string {
	unchecksummed := hex.EncodeToString(a[:])
	sha := sha3.NewLegacyKeccak256()
	sha.Write([]byte(unchecksummed))
	hash := sha.Sum(nil)

	result := []byte(unchecksummed)
	for i := 0; i < len(result); i++ {
		hashByte := hash[i/2]
		if i%2 == 0 {
			hashByte = hashByte >> 4
		} else {
			hashByte &= 0xf
		}
		if result[i] > '9' && hashByte > 7 {
			result[i] -= 32
		}
	}
	return "0x" + string(result)
}
909474
func (a Address) Key() string {
	res := ""
	if a.Scheme != "" {
		res += a.Scheme + "://"
	}
	if a.Host != "" {
		res += a.Host
	}
	if a.Port != "" {
		if strings.HasPrefix(a.Original[len(res):], ":"+a.Port) {
			// insert port only if the original has its own explicit port
			res += ":" + a.Port
		}
	}
	if a.Path != "" {
		res += a.Path
	}
	return res
}