Sha256: 0b98e81de6eae5c9fb8ddd84ee2395bc5e6f408b8cdb6d36da1b7d39f9d4c945

Contents?: true

Size: 694 Bytes

Versions: 16

Compression:

Stored size: 694 Bytes

Contents

package keychain

import (
	"crypto/rand"
	"encoding/base32"
	"strings"
)

var randRead = rand.Read

// RandomID returns random ID (base32) string with prefix, using 256 bits as
// recommended by tptacek: https://gist.github.com/tqbf/be58d2d39690c3b366ad
func RandomID(prefix string) (string, error) {
	buf, err := RandBytes(32)
	if err != nil {
		return "", err
	}
	str := base32.StdEncoding.EncodeToString(buf)
	str = strings.Replace(str, "=", "", -1)
	str = prefix + str
	return str, nil
}

// RandBytes returns random bytes of length
func RandBytes(length int) ([]byte, error) {
	buf := make([]byte, length)
	if _, err := randRead(buf); err != nil {
		return nil, err
	}
	return buf, nil
}

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ruby_snowflake_client-1.3.7 ext/vendor/github.com/99designs/go-keychain/util.go
ruby_snowflake_client-1.3.6 ext/vendor/github.com/99designs/go-keychain/util.go
ruby_snowflake_client-1.3.5 ext/vendor/github.com/99designs/go-keychain/util.go
ruby_snowflake_client-1.3.4 ext/vendor/github.com/99designs/go-keychain/util.go
ruby_snowflake_client-1.3.4.pre.debug ext/vendor/github.com/99designs/go-keychain/util.go
ruby_snowflake_client-1.3.3.pre.debug ext/vendor/github.com/99designs/go-keychain/util.go
ruby_snowflake_client-1.3.2 ext/vendor/github.com/99designs/go-keychain/util.go
ruby_snowflake_client-1.3.1 ext/vendor/github.com/99designs/go-keychain/util.go
ruby_snowflake_client-1.3.0 ext/vendor/github.com/99designs/go-keychain/util.go
ruby_snowflake_client-1.2.1 ext/vendor/github.com/99designs/go-keychain/util.go
ruby_snowflake_client-1.2.0 ext/vendor/github.com/99designs/go-keychain/util.go
ruby_snowflake_client-1.1.1 ext/vendor/github.com/99designs/go-keychain/util.go
ruby_snowflake_client-1.1.0 ext/vendor/github.com/99designs/go-keychain/util.go
ruby_snowflake_client-1.0.2 ext/vendor/github.com/99designs/go-keychain/util.go
ruby_snowflake_client-1.0.1 ext/vendor/github.com/99designs/go-keychain/util.go
ruby_snowflake_client-1.0.0 ext/vendor/github.com/99designs/go-keychain/util.go