idutil

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// UserIDRange: 8 digits [10,000,000, 99,999,999]
	MinUserID = 10000000
	MaxUserID = 99999999

	// RoleIDRange: 9 digits [100,000,000, 199,999,999]
	MinRoleID = 100000000
	MaxRoleID = 199999999

	// PolicyIDRange: 9 digits [200,000,000, 299,999,999]
	MinPolicyID = 200000000
	MaxPolicyID = 299999999

	// GroupIDRange: 9 digits [300,000,000, 399,999,999]
	MinGroupID = 300000000
	MaxGroupID = 399999999

	// AccessKeyIDRange: 9 digits [400,000,000, 499,999,999]
	MinAccessKeyID = 400000000
	MaxAccessKeyID = 499999999

	// AccountIDRange: 10 digits [1,000,000,000, 2,147,483,647] (Fits in int32)
	MinAccountID = 1000000000
	MaxAccountID = 2147483647
)
View Source
var DefaultKey = []byte("arrow2012-secret-key-salt")

DefaultKey is the encryption key for ID obfuscation. In production, this should be configurable.

Functions

func DecodeAccessKeyID

func DecodeAccessKeyID(publicID int) int

func DecodeAccountID

func DecodeAccountID(publicID int) int

DecodeAccountID restores 10-digit Public ID to internal ID.

func DecodeGroupID

func DecodeGroupID(publicID int) int

func DecodePolicyID

func DecodePolicyID(publicID int) int

func DecodeRoleID

func DecodeRoleID(publicID int) int

func DecodeUserID

func DecodeUserID(publicID int) int

DecodeUserID restores 8-digit Public ID to internal ID.

func DecryptRange

func DecryptRange(val, min, max int) int

DecryptRange restores value from EncryptRange

func EncodeAccessKeyID

func EncodeAccessKeyID(id int) int

AccessKey Helpers (for ID, not the string key)

func EncodeAccountID

func EncodeAccountID(id int) int

EncodeAccountID maps internal ID to 10-digit Public ID.

func EncodeGroupID

func EncodeGroupID(id int) int

Group Helpers

func EncodePolicyID

func EncodePolicyID(id int) int

Policy Helpers

func EncodeRoleID

func EncodeRoleID(id int) int

Role Helpers

func EncodeUserID

func EncodeUserID(id int) int

EncodeUserID maps internal ID (1, 2...) to 8-digit Public ID.

func EncryptRange

func EncryptRange(val, min, max int) int

EncryptRange maps a value strictly within [min, max] to another value in [min, max] reversibly. It assumes the input `val` is already within [min, max].

Types

type FeistelCipher

type FeistelCipher struct {
	// contains filtered or unexported fields
}

FeistelCipher implements a format-preserving encryption for integers. It maps a 32-bit integer to another 32-bit integer reversibly.

func NewFeistelCipher

func NewFeistelCipher(key []byte) *FeistelCipher

func (*FeistelCipher) Decrypt

func (fc *FeistelCipher) Decrypt(id uint32) uint32

Decrypt restores the original ID

func (*FeistelCipher) Encrypt

func (fc *FeistelCipher) Encrypt(id uint32) uint32

Encrypt obfuscates a uint32 ID

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL