// NewV4 returns random generated UUID.
337969
func NewV4() (UUID, error) {
	u := UUID{}
	if _, err := randomReader.Read(u[:]); err != nil {
		return Nil, err
	}
	u.setVersion(V4)
	u.setVariant(VariantRFC4122)

	return u, nil
}
1340739
func NewUUIDv1() (UUID, error) {
	uuid := UUID{}
	epoch := int64(0x01b21dd213814000)
	now := uint64(time.Now().UnixNano()/100 + epoch)

	clockSeqRand := [2]byte{}
	rand.Read(clockSeqRand[:])
	clockSeq := binary.LittleEndian.Uint16(clockSeqRand[:])

	timeLow := uint32(now & (0x100000000 - 1))
	timeMid := uint16((now >> 32) & 0xffff)
	timeHighVer := uint16((now >> 48) & 0x0fff)
	clockSeq &= 0x3fff

	binary.LittleEndian.PutUint32(uuid[0:4], timeLow)
	binary.LittleEndian.PutUint16(uuid[4:6], timeMid)
	binary.LittleEndian.PutUint16(uuid[6:8], timeHighVer)
	binary.LittleEndian.PutUint16(uuid[8:10], clockSeq)
	copy(uuid[10:16], cachedMACAddress)

	uuid.setVersion(UUIDv1)
	uuid.setVariant(UUIDVariantRFC4122)
	return uuid, nil
}
612285
func NewV4SigningClient(creds *credentials.Credentials, region string) *http.Client {
	return NewV4SigningClientWithHTTPClient(creds, region, http.DefaultClient)
}
721430
func NewV4(pubkey *ecdsa.PublicKey, ip net.IP, tcp, udp int) *Node {
	var r enr.Record
	if ip != nil {
		r.Set(enr.IP(ip))
	}
	if udp != 0 {
		r.Set(enr.UDP(udp))
	}
	if tcp != 0 {
		r.Set(enr.TCP(tcp))
	}
	signV4Compat(&r, pubkey)
	n, err := New(v4CompatID{}, &r)
	if err != nil {
		panic(err)
	}
	return n
}
817610
func New364(seed uint64) nhash.Hash64 {
	s := new(State364)
	s.seed = seed
	s.Reset()
	return s
}
720401
func New224() hash.Hash {
	d := new(digest)
	d.is224 = true
	d.Reset()
	return d
}
23380
func NewV4Options(req *http.Request) (*V4Options, error) {
	if !wsstream.IsWebSocketRequest(req) {
		return &V4Options{}, nil
	}

	portStrings := req.URL.Query()[api.PortHeader]
	if len(portStrings) == 0 {
		return nil, fmt.Errorf("query parameter %q is required", api.PortHeader)
	}

	ports := make([]int32, 0, len(portStrings))
	for _, portString := range portStrings {
		if len(portString) == 0 {
			return nil, fmt.Errorf("query parameter %q cannot be empty", api.PortHeader)
		}
		for _, p := range strings.Split(portString, ",") {
			port, err := strconv.ParseUint(p, 10, 16)
			if err != nil {
				return nil, fmt.Errorf("unable to parse %q as a port: %v", portString, err)
			}
			if port < 1 {
				return nil, fmt.Errorf("port %q must be > 0", portString)
			}
			ports = append(ports, int32(port))
		}
	}

	return &V4Options{
		Ports: ports,
	}, nil
}
840158
func UUIDv4() (uuid UUID, err error) {
	// Get 16 random bytes
	b, err := GetBytes(16)
	if err != nil {
		return
	}

	_, err = io.ReadFull(bytes.NewBuffer(b), uuid[:])
	if err != nil {
		return
	}

	uuid[6] = (uuid[6] & 0x0f) | 0x40 // Version 4
	uuid[8] = (uuid[8] & 0x3f) | 0x80 // Variant is 10

	return
}
479248
func (g *rfc4122Generator) NewV2(domain byte) (UUID, error) {
	u, err := g.NewV1()
	if err != nil {
		return Nil, err
	}

	switch domain {
	case DomainPerson:
		binary.BigEndian.PutUint32(u[:], posixUID)
	case DomainGroup:
		binary.BigEndian.PutUint32(u[:], posixGID)
	}

	u[9] = domain

	u.SetVersion(V2)
	u.SetVariant(VariantRFC4122)

	return u, nil
}
72134
func NewV3(ns UUID, name string) UUID {
	u := newFromHash(md5.New(), ns, name)
	u.SetVersion(3)
	u.SetVariant()

	return u
}
624241
func NewUUID() UUID {
	uuid, err := NewUUIDv4()
	if err != nil {
		// Panic due to compatibility reasons.
		panic(err)
	}
	return uuid
}
960487
func New(queueID uint16, maxPacketsInQueue uint32, packetSize uint32) (nfq *Queue, err error) {
	nfq = &Queue{
		ID: queueID,
		// TODO: what should the chan size be?
		packets: make(chan *RawPacket, 1024),
	}
	var ret C.int

	defer func() {
		if err != nil && nfq != nil {
			if nfq.qh != nil {
				C.nfq_destroy_queue(nfq.qh)
			}

			if nfq.h != nil {
				C.nfq_close(nfq.h)
			}
		}
	}()

	if nfq.h, err = C.nfq_open(); err != nil {
		err = errors.Wrap(err, "netfilter: unable to open nfq queue handle.")
		return
	}

	if ret, err = C.nfq_unbind_pf(nfq.h, AF_INET); err != nil || ret < 0 {
		err = errors.Wrap(err, "netfilter: unable to unbind existing nfq handler.")
		return
	}

	if ret, err = C.nfq_bind_pf(nfq.h, AF_INET); err != nil || ret < 0 {
		err = errors.Wrap(err, "netfilter: unable to bind to AF_INET protocol family.")
		return
	}

	if nfq.qh, err = C.CreateQueue(nfq.h, C.u_int16_t(queueID)); err != nil || nfq.qh == nil {
		err = errors.Wrap(err, "netfilter: unable to create nfq queue.")
		return
	}

	if ret, err = C.nfq_set_queue_maxlen(nfq.qh, C.u_int32_t(maxPacketsInQueue)); err != nil || ret < 0 {
		err = errors.Wrap(err, "netfilter: unable to set nfq max queue length.")
		return
	}

	if C.nfq_set_mode(nfq.qh, C.u_int8_t(2), C.uint(packetSize)) < 0 {
		err = errors.Wrap(err, "netfilter: unable to set packet copy mode.")
		return
	}

	if nfq.fd, err = C.nfq_fd(nfq.h); err != nil {
		err = errors.Wrap(err, "netfilter: unable to get nfq queue file-descriptor.")
		return

	}

	// TODO: error handling
	// me: https://i.imgur.com/Lmy5P.gif
	C.nfnl_rcvbufsiz(C.nfq_nfnlh(nfq.h), 1024*16384)

	// register this queue object with the global dispatcher
	register(queueID, nfq.packets)

	return
}
592105
func NewUUIDByHex(source string) (UUID, error) {
	uuid := UUID{}
	if len([]byte(source)) != 32 {
		return uuid, errors.New(ErrInvalidHexLength, errorMessages)
	}
	raw, err := hex.DecodeString(source)
	if err != nil {
		return uuid, errors.Annotate(err, ErrInvalidHexValue, errorMessages)
	}
	copy(uuid[:], raw)
	return uuid, nil
}
661118
func New224() hash.Hash {
	if h := new224Asm(); h != nil {
		return h
	}
	return &state{rate: 144, outputLen: 28, dsbyte: 0x01}
}
908739
func NewL3n4AddrID(protocol L4Type, ip net.IP, portNumber uint16, id ID) *L3n4AddrID {
	l3n4Addr := NewL3n4Addr(protocol, ip, portNumber)
	return &L3n4AddrID{L3n4Addr: *l3n4Addr, ID: id}
}
738644
func NewV5(ns UUID, name string) UUID {
	u := newFromHash(sha1.New(), ns, name)
	u.SetVersion(5)
	u.SetVariant()

	return u
}
1028153
func NewV4() (*GUID, error) {
	var b [16]byte
	if _, err := rand.Read(b[:]); err != nil {
		return nil, err
	}

	var g GUID
	g.Data1 = binary.LittleEndian.Uint32(b[0:4])
	g.Data2 = binary.LittleEndian.Uint16(b[4:6])
	g.Data3 = binary.LittleEndian.Uint16(b[6:8])
	copy(g.Data4[:], b[8:16])

	g.Data3 = (g.Data3 & 0x0fff) | 0x4000   // Version 4 (randomly generated)
	g.Data4[0] = (g.Data4[0] & 0x3f) | 0x80 // RFC4122 variant
	return &g, nil
}