Files
pulse/internal/license/license.go
T
rcourtman faefe6edc8 Remove 198 unreachable Go functions
Dead-code sweep. Functions flagged unreachable by golang.org/x/tools/cmd/deadcode
and confirmed unused across pulse, pulse-enterprise, pulse-pro and pulse-mobile by
adversarial cross-repo verification. Cross-module reachability was checked
explicitly (only pkg/ exported symbols are importable by other modules; internal/
packages and _test.go files are not). go build, go vet and test-compile all pass.
2026-06-03 12:29:37 +01:00

97 lines
2.5 KiB
Go

package license
import (
"crypto/ed25519"
"os"
"strings"
"sync"
"github.com/rcourtman/pulse-go-rewrite/internal/license/entitlements"
pkglicensing "github.com/rcourtman/pulse-go-rewrite/pkg/licensing"
)
// Compatibility-only mirror for existing internal tests.
var (
publicKeyMu sync.RWMutex
publicKey ed25519.PublicKey
)
func SetPublicKey(key ed25519.PublicKey) {
publicKeyMu.Lock()
if len(key) == 0 {
publicKey = nil
} else {
keyCopy := make(ed25519.PublicKey, len(key))
copy(keyCopy, key)
publicKey = keyCopy
}
publicKeyMu.Unlock()
pkglicensing.SetPublicKey(key)
}
var (
ErrInvalidLicense = pkglicensing.ErrInvalidLicense
ErrExpiredLicense = pkglicensing.ErrExpiredLicense
ErrMalformedLicense = pkglicensing.ErrMalformedLicense
ErrSignatureInvalid = pkglicensing.ErrSignatureInvalid
ErrFeatureNotIncluded = pkglicensing.ErrFeatureNotIncluded
ErrNoPublicKey = pkglicensing.ErrNoPublicKey
)
type SubscriptionState = entitlements.SubscriptionState
const (
SubStateTrial = entitlements.SubStateTrial
SubStateActive = entitlements.SubStateActive
SubStateGrace = entitlements.SubStateGrace
SubStateExpired = entitlements.SubStateExpired
SubStateSuspended = entitlements.SubStateSuspended
SubStateCanceled = entitlements.SubStateCanceled
)
type LimitCheckResult = entitlements.LimitCheckResult
const (
LimitAllowed = entitlements.LimitAllowed
LimitSoftBlock = entitlements.LimitSoftBlock
LimitHardBlock = entitlements.LimitHardBlock
)
type Claims = pkglicensing.Claims
type License = pkglicensing.License
type LicenseState = pkglicensing.LicenseState
type LicenseStatus = pkglicensing.LicenseStatus
const (
LicenseStateNone = pkglicensing.LicenseStateNone
LicenseStateActive = pkglicensing.LicenseStateActive
LicenseStateExpired = pkglicensing.LicenseStateExpired
LicenseStateGracePeriod = pkglicensing.LicenseStateGracePeriod
)
const (
DefaultGracePeriod = pkglicensing.DefaultGracePeriod
// Compatibility constants retained for existing tests.
maxLicenseKeyLength = 16 << 10 // 16 KiB
maxLicenseSegmentLength = 8 << 10 // 8 KiB
maxLicensePayloadSize = 8 << 10 // 8 KiB decoded JSON
)
type Service struct {
*pkglicensing.Service
}
func NewService() *Service {
return &Service{Service: pkglicensing.NewService()}
}
func ValidateLicense(licenseKey string) (*License, error) {
return pkglicensing.ValidateLicense(licenseKey)
}
func isLicenseValidationDevMode() bool {
return strings.EqualFold(strings.TrimSpace(os.Getenv("PULSE_LICENSE_DEV_MODE")), "true")
}