enterprise

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package enterprise provides per-enterprise configuration and secret management for Tier 2.5 hierarchical private search.

Each enterprise has its own:

  • AES-256 key for vector encryption
  • LSH seed for secret hyperplane generation
  • Centroids for HE scoring

These secrets are distributed to authenticated users via the auth service, ensuring that the server cannot map bucket IDs to query regions.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEnterpriseNotFound is returned when an enterprise configuration is not found.
	ErrEnterpriseNotFound = errors.New("enterprise not found")
	// ErrEnterpriseExists is returned when trying to create an enterprise that already exists.
	ErrEnterpriseExists = errors.New("enterprise already exists")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// EnterpriseID uniquely identifies the enterprise
	EnterpriseID string

	// AESKey is the 256-bit key for vector encryption (32 bytes)
	AESKey []byte

	// LSHSeed is the cryptographically random seed for LSH hyperplanes
	// This is SECRET - unlike the current public seeds (42, 137)
	LSHSeed []byte // 32 bytes

	// Centroids are the super-bucket centroids for HE scoring
	// These can be cached client-side after authentication
	Centroids [][]float64

	// Dimension is the vector dimension
	Dimension int

	// NumSuperBuckets is the number of super-buckets
	NumSuperBuckets int

	// NumSubBuckets is the number of sub-buckets (within each super-bucket)
	NumSubBuckets int

	// Metadata
	CreatedAt   time.Time
	UpdatedAt   time.Time
	Version     int
	Description string
}

Config holds all enterprise-specific secrets and configuration. This is distributed to authenticated users via the auth service.

func LoadConfig

func LoadConfig(r io.Reader) (*Config, error)

LoadConfig deserializes a configuration from a reader.

func LoadConfigFromFile

func LoadConfigFromFile(path string) (*Config, error)

LoadConfigFromFile loads a configuration from a file.

func NewConfig

func NewConfig(enterpriseID string, dimension int, numSuperBuckets int) (*Config, error)

NewConfig creates a new enterprise configuration with fresh secrets. Uses default of 64 sub-buckets.

func NewConfigWithSubBuckets

func NewConfigWithSubBuckets(enterpriseID string, dimension int, numSuperBuckets int, numSubBuckets int) (*Config, error)

NewConfigWithSubBuckets creates a new enterprise configuration with custom sub-bucket count.

func (*Config) Clone

func (c *Config) Clone() *Config

Clone creates a deep copy of the configuration.

func (*Config) Fingerprint

func (c *Config) Fingerprint() string

Fingerprint returns a safe identifier for logging (not the full key).

func (*Config) GetLSHSeedAsInt64

func (c *Config) GetLSHSeedAsInt64() int64

GetLSHSeedAsInt64 returns the LSH seed as int64 for compatibility with the existing lsh.Index which uses int64 seeds.

func (*Config) GetSubLSHBits

func (c *Config) GetSubLSHBits() int

GetSubLSHBits returns the number of LSH bits for sub-buckets. This must match what the builder uses for consistent hashing.

func (*Config) GetSubLSHSeedAsInt64

func (c *Config) GetSubLSHSeedAsInt64() int64

GetSubLSHSeedAsInt64 returns a derived seed for sub-bucket LSH. Uses XOR with a constant to derive a different but deterministic seed.

func (*Config) Save

func (c *Config) Save(w io.Writer) error

Save serializes the configuration to a writer.

func (*Config) SaveToFile

func (c *Config) SaveToFile(path string) error

SaveToFile saves the configuration to a file.

func (*Config) SetCentroids

func (c *Config) SetCentroids(centroids [][]float64)

SetCentroids updates the centroids (called after index building).

func (*Config) Validate

func (c *Config) Validate() error

Validate checks that the configuration is complete and valid.

type FileStore

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

FileStore implements Store using filesystem storage. Each enterprise config is stored as a separate file.

func NewFileStore

func NewFileStore(baseDir string) (*FileStore, error)

NewFileStore creates a file-based configuration store.

func (*FileStore) Close

func (s *FileStore) Close() error

Close closes the store.

func (*FileStore) Delete

func (s *FileStore) Delete(ctx context.Context, enterpriseID string) error

Delete removes an enterprise configuration.

func (*FileStore) Exists

func (s *FileStore) Exists(ctx context.Context, enterpriseID string) bool

Exists checks if an enterprise exists.

func (*FileStore) Get

func (s *FileStore) Get(ctx context.Context, enterpriseID string) (*Config, error)

Get retrieves an enterprise configuration by ID.

func (*FileStore) List

func (s *FileStore) List(ctx context.Context) ([]string, error)

List returns all enterprise IDs.

func (*FileStore) Put

func (s *FileStore) Put(ctx context.Context, cfg *Config) error

Put stores or updates an enterprise configuration.

type MemoryStore

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

MemoryStore implements Store using in-memory storage. For production, implement a secure vault-backed store.

func NewMemoryStore

func NewMemoryStore() *MemoryStore

NewMemoryStore creates an in-memory configuration store.

func (*MemoryStore) Close

func (s *MemoryStore) Close() error

Close closes the store.

func (*MemoryStore) Delete

func (s *MemoryStore) Delete(ctx context.Context, enterpriseID string) error

Delete removes an enterprise configuration.

func (*MemoryStore) Exists

func (s *MemoryStore) Exists(ctx context.Context, enterpriseID string) bool

Exists checks if an enterprise exists.

func (*MemoryStore) Get

func (s *MemoryStore) Get(ctx context.Context, enterpriseID string) (*Config, error)

Get retrieves an enterprise configuration by ID.

func (*MemoryStore) List

func (s *MemoryStore) List(ctx context.Context) ([]string, error)

List returns all enterprise IDs.

func (*MemoryStore) Put

func (s *MemoryStore) Put(ctx context.Context, cfg *Config) error

Put stores or updates an enterprise configuration.

type Store

type Store interface {
	// Get retrieves an enterprise configuration by ID.
	Get(ctx context.Context, enterpriseID string) (*Config, error)

	// Put stores or updates an enterprise configuration.
	Put(ctx context.Context, cfg *Config) error

	// Delete removes an enterprise configuration.
	Delete(ctx context.Context, enterpriseID string) error

	// List returns all enterprise IDs.
	List(ctx context.Context) ([]string, error)

	// Exists checks if an enterprise exists.
	Exists(ctx context.Context, enterpriseID string) bool

	// Close closes the store.
	Close() error
}

Store is the interface for enterprise configuration storage.

Jump to

Keyboard shortcuts

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