// NewV2 returns DCE Security UUID based on POSIX UID/GID.
967782
func NewV2(domain byte) UUID {
	u := UUID{}

	timeNow, clockSeq, hardwareAddr := getStorage()

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

	binary.BigEndian.PutUint16(u[4:], uint16(timeNow>>32))
	binary.BigEndian.PutUint16(u[6:], uint16(timeNow>>48))
	binary.BigEndian.PutUint16(u[8:], clockSeq)
	u[9] = domain

	copy(u[10:], hardwareAddr)

	u.SetVersion(2)
	u.SetVariant()

	return u
}
973283
func NewCidV0(mhash mh.Multihash) Cid {
	// Need to make sure hash is valid for CidV0 otherwise we will
	// incorrectly detect it as CidV1 in the Version() method
	dec, err := mh.Decode(mhash)
	if err != nil {
		panic(err)
	}
	if dec.Code != mh.SHA2_256 || dec.Length != 32 {
		panic("invalid hash for cidv0")
	}
	return Cid{string(mhash)}
}
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
}
1245082
func (g *rfc4122Generator) NewV5(ns UUID, name string) UUID {
	u := newFromHash(sha1.New(), ns, name)
	u.SetVersion(V5)
	u.SetVariant(VariantRFC4122)

	return u
}
1155334
func NewUid() uint64 {
	b := make([]byte, 8)
	ts := uint32(time.Now().Unix()) - ourEpoch

	// Timestamp, 4 bytes, big endian
	binary.BigEndian.PutUint32(b, ts)
	//Debugf("ts=%v   b=%v", ts, b)
	// first 3 bytes of host/pid
	b[4] = hostPidId[2]
	b[5] = hostPidId[3]
	b[6] = hostPidId[3]
	// Increment, 2 bytes, big endian
	i := atomic.AddUint32(&uidCounter, 1)
	//b[6] = byte(i >> 8)
	b[7] = byte(i)
	ui := binary.BigEndian.Uint64(b)
	//Debugf("ui=%d  b=%v ", ui, b)
	return ui
}
301786
func New() *AnonUUID {
	return &AnonUUID{
		cache:    make(map[string]string),
		Hexspeak: false,
		Random:   false,
	}
}
1048989
func NewUUIDv3(ns UUID, name []byte) (UUID, error) {
	uuid := UUID{}
	hash := md5.New()
	hash.Write(ns.dump())
	hash.Write(name)
	copy(uuid[:], hash.Sum([]byte{})[:16])

	uuid.setVersion(UUIDv3)
	uuid.setVariant(UUIDVariantRFC4122)
	return uuid, nil
}
417409
func New(errMsg string) Error {
	uidv4, _ := uuid.NewV4() // skip error.
	return Error{
		ID:      uidv4.String(),
		Message: Prefix + errMsg,
	}
}
1021188
func (o *Generator) NewV1() UUID {
	o.read()
	id := UUID{}

	makeUuid(&id,
		uint32(o.Timestamp),
		uint16(o.Timestamp>>32),
		uint16(o.Timestamp>>48),
		uint16(o.Sequence),
		o.Node)

	id.setRFC4122Version(VersionOne)
	return id
}
809775
func PostPresignSignatureV2(policyBase64, secretAccessKey string) string {
	hm := hmac.New(sha1.New, []byte(secretAccessKey))
	hm.Write([]byte(policyBase64))
	signature := base64.StdEncoding.EncodeToString(hm.Sum(nil))
	return signature
}
1159948
func NewUUID(domain Domain) ([]byte, error) {
	uuid, err := timebased.NewUUID()
	if err != nil {
		return nil, err
	}

	switch domain {
	case User:
		uid := os.Getuid()
		binary.BigEndian.PutUint32(uuid[0:], uint32(uid)) // network byte order
	case Group:
		gid := os.Getgid()
		binary.BigEndian.PutUint32(uuid[0:], uint32(gid)) // network byte order
	default:
		return nil, errors.New("domain is invalid")
	}

	// set version(v2)
	internal.SetVersion(uuid, internal.VersionDCESecurity)
	// set layout(RFC4122)
	internal.SetLayout(uuid, internal.LayoutRFC4122)

	return uuid, nil
}
1094760
func (o *Generator) NewV3(namespace Implementation, names ...interface{}) UUID {
	id := UUID{}
	id.unmarshal(digest(md5.New(), namespace.Bytes(), names...))
	id.setRFC4122Version(VersionThree)
	return id
}
1348136
func NewGUID() GUID {
	result, err := version4()
	if err != nil {
		panic(err) //Version 4 (pseudo-random GUID) doesn't use anything that could fail.
	}
	return result
}
602733
func New() *Vangoh {
	return &Vangoh{
		singleProvider:  nil,
		providersByOrg:  make(map[string]secretProvider),
		algorithm:       crypto.SHA256.New,
		includedHeaders: make(map[string]*regexp.Regexp),
		maxTimeSkew:     time.Minute * 15,
		debug:           false,
	}
}
555698
func NewUUID62() (string, error) {
	b := make([]byte, 16)
	_, err := randSource.Read(b)
	if err != nil {
		return "", err
	}
	s := fmt.Sprintf("%x", b)
	return ConvertUp(s, base62alphabet), nil
}
434885
func NewUUIDv5(ns UUID, name []byte) (UUID, error) {
	uuid := UUID{}
	hash := sha1.New()
	hash.Write(ns.dump())
	hash.Write(name)
	copy(uuid[:], hash.Sum([]byte{})[:16])

	uuid.setVersion(UUIDv5)
	uuid.setVariant(UUIDVariantRFC4122)
	return uuid, nil
}
1226937
func newUUID() (string, error) {
	uuid := make([]byte, 16)
	if _, err := io.ReadFull(rand.Reader, uuid); err != nil {
		return "", err
	}
	// variant bits; see section 4.1.1
	uuid[8] = uuid[8]&^0xc0 | 0x80
	// version 4 (pseudo-random); see section 4.1.3
	uuid[6] = uuid[6]&^0xf0 | 0x40
	return fmt.Sprintf("%x-%x-%x-%x-%x", uuid[0:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:]), nil
}