Module: Baseh

Defined in:
lib/baseh.rb,
lib/baseh/baseh.rb,
lib/baseh/basen.rb,
lib/baseh/errors.rb,
lib/baseh/feistel.rb,
lib/baseh/profile.rb,
lib/baseh/version.rb,
lib/baseh/checksum.rb,
lib/baseh/profiles.rb,
lib/baseh/profanity.rb

Overview

baseH (Human Reference Code) codec. See spec/IMPLEMENTATION_CODEC.md in the repository root for the normative specification.

Defined Under Namespace

Modules: BaseN, Checksum, Feistel, Profanity, Profile, Profiles Classes: Baseh, BasehError

Constant Summary collapse

FROZEN_KEY_BYTES =

The frozen published permutation key used by every plain tier helper. Public by design: it makes issued codes look non-sequential but offers no secrecy, since anyone can read it here. Never swap it on a live namespace; codes only decode with the key they were issued under. Use the -p helpers to supply private key material.

Profiles::FROZEN_KEY_BYTES
VERSION =
"2.0.3"

Class Method Summary collapse

Class Method Details

.baseh_expandable_p_v1(key_bytes:, key_id: "default", rounds: 8) ⇒ Object

baseh-expandable permuted with caller-supplied key material. key_bytes is required.



80
81
82
# File 'lib/baseh.rb', line 80

def baseh_expandable_p_v1(key_bytes:, key_id: "default", rounds: 8)
  Profiles.baseh_expandable_p_v1(key_bytes: key_bytes, key_id: key_id, rounds: rounds)
end

.baseh_expandable_v1Object

Frozen tier baseh-expandable-v1: variable-length codes, four characters while the namespace is small and growing one symbol per generation. Permutes per generation with the frozen published key.



75
76
77
# File 'lib/baseh.rb', line 75

def baseh_expandable_v1
  Profiles.baseh_expandable_v1
end

.baseh_heavy_p_v1(key_bytes:, key_id: "default", rounds: 8) ⇒ Object

baseh-heavy permuted with caller-supplied key material. key_bytes is required.



68
69
70
# File 'lib/baseh.rb', line 68

def baseh_heavy_p_v1(key_bytes:, key_id: "default", rounds: 8)
  Profiles.baseh_heavy_p_v1(key_bytes: key_bytes, key_id: key_id, rounds: rounds)
end

.baseh_heavy_v1Object

Frozen tier baseh-heavy-v1: conservative alphabet plus spoken heavy, two checksum symbols, hyphen-delimited. Permutes with the frozen published key.



63
64
65
# File 'lib/baseh.rb', line 63

def baseh_heavy_v1
  Profiles.baseh_heavy_v1
end

.baseh_light_p_v1(key_bytes:, key_id: "default", rounds: 8) ⇒ Object

baseh-light permuted with caller-supplied key material. key_bytes is required.



44
45
46
# File 'lib/baseh.rb', line 44

def baseh_light_p_v1(key_bytes:, key_id: "default", rounds: 8)
  Profiles.baseh_light_p_v1(key_bytes: key_bytes, key_id: key_id, rounds: rounds)
end

.baseh_light_v1Object

Frozen tier baseh-light-v1: visual light plus spoken light, two checksum symbols, hyphen-delimited. Permutes with the frozen published key.



39
40
41
# File 'lib/baseh.rb', line 39

def baseh_light_v1
  Profiles.baseh_light_v1
end

.baseh_medium_p_v1(key_bytes:, key_id: "default", rounds: 8) ⇒ Object

baseh-medium permuted with caller-supplied key material. key_bytes is required.



56
57
58
# File 'lib/baseh.rb', line 56

def baseh_medium_p_v1(key_bytes:, key_id: "default", rounds: 8)
  Profiles.baseh_medium_p_v1(key_bytes: key_bytes, key_id: key_id, rounds: rounds)
end

.baseh_medium_v1Object

Frozen tier baseh-medium-v1: visual medium plus spoken medium, two checksum symbols, hyphen-delimited. The default. Permutes with the frozen published key.



51
52
53
# File 'lib/baseh.rb', line 51

def baseh_medium_v1
  Profiles.baseh_medium_v1
end

.baseh_minimum_p_v1(key_bytes:, key_id: "default", rounds: 8) ⇒ Object

baseh-minimum permuted with caller-supplied key material. key_bytes is required.



32
33
34
# File 'lib/baseh.rb', line 32

def baseh_minimum_p_v1(key_bytes:, key_id: "default", rounds: 8)
  Profiles.baseh_minimum_p_v1(key_bytes: key_bytes, key_id: key_id, rounds: rounds)
end

.baseh_minimum_v1Object

Frozen tier baseh-minimum-v1: alphanumeric with no strips, no checksum, hyphen-delimited XXX-XXX. Permutes with the frozen published key.



27
28
29
# File 'lib/baseh.rb', line 27

def baseh_minimum_v1
  Profiles.baseh_minimum_v1
end

.decode(input, **options) ⇒ Baseh::Baseh::DecodeResult

Decode a code from the default expandable profile.

Parameters:

  • input (String)
  • options

    keyword options of Baseh::Baseh#decode (accept_spaces:, try_correction:, confusion_profile:, max_corrections:)

Returns:

Raises:

  • (BasehError)

    same codes as the instance decode



113
114
115
# File 'lib/baseh.rb', line 113

def decode(input, **options)
  default.decode(input, **options)
end

.defaultObject

The shared default-profile codec, built on first use.



137
138
139
# File 'lib/baseh.rb', line 137

def default
  @default ||= Baseh.new(Profiles.baseh_expandable_v1)
end

.encode(id) ⇒ String

Encode an identifier with the default expandable profile.

Parameters:

  • id (Integer)

    any non-negative id

Returns:

  • (String)

    canonical code

Raises:



102
103
104
# File 'lib/baseh.rb', line 102

def encode(id)
  default.encode(id: id)
end

.inspect(input) ⇒ Baseh::Baseh::InspectResult

Live as-you-type inspection of input against the default expandable profile (spec 12.5). Never raises on user input.

Parameters:

  • input (String)

Returns:



122
123
124
# File 'lib/baseh.rb', line 122

def inspect(input)
  default.inspect(input)
end

.validate(input, **options) ⇒ Baseh::Baseh::ValidateResult

Validate a code against the default expandable profile without raising.

Parameters:

  • input (String)
  • options

    keyword options of Baseh::Baseh#validate (the same keyword options decode accepts)

Returns:



132
133
134
# File 'lib/baseh.rb', line 132

def validate(input, **options)
  default.validate(input, **options)
end