Skip to content

Conversation

@patapenka-alexey
Copy link
Contributor

@patapenka-alexey patapenka-alexey commented Nov 26, 2025

Closes TNTP-4190

@patapenka-alexey patapenka-alexey force-pushed the patapenka-alexey/tntp-4190-namer branch from e331f55 to 5eb96c6 Compare November 26, 2025 05:17
@coveralls
Copy link

coveralls commented Nov 26, 2025

Pull Request Test Coverage Report for Build 19822144009

Details

  • 91 of 130 (70.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+2.1%) to 22.309%

Changes Missing Coverage Covered Lines Changed/Added Lines %
namer/generatorvalidator.go 48 87 55.17%
Totals Coverage Status
Change from base Build 19701817310: 2.1%
Covered Lines: 688
Relevant Lines: 3084

💛 - Coveralls

@patapenka-alexey patapenka-alexey force-pushed the patapenka-alexey/tntp-4190-namer branch from 5eb96c6 to 9c15fdc Compare November 26, 2025 08:15
@patapenka-alexey patapenka-alexey force-pushed the patapenka-alexey/tntp-4190-namer branch 3 times, most recently from 082bc61 to 5e8e064 Compare November 27, 2025 06:41
@patapenka-alexey patapenka-alexey marked this pull request as ready for review November 27, 2025 06:42
@patapenka-alexey patapenka-alexey changed the title namer/signer/verifier: implementation namer/generator/validator: implementation Nov 28, 2025
@patapenka-alexey patapenka-alexey force-pushed the patapenka-alexey/tntp-4190-namer branch from 5e8e064 to a0bda45 Compare November 28, 2025 06:09
@oleg-jukovec
Copy link
Collaborator

api: implement namer, generator, validator

Please, change the commit title and the PR title.

@patapenka-alexey patapenka-alexey force-pushed the patapenka-alexey/tntp-4190-namer branch from a0bda45 to a5ddaf9 Compare November 28, 2025 13:43
@patapenka-alexey patapenka-alexey changed the title namer/generator/validator: implementation api: implement namer, generator, validator Nov 28, 2025
@oleg-jukovec oleg-jukovec requested review from elhimov and removed request for oleg-jukovec December 1, 2025 10:39
@patapenka-alexey patapenka-alexey force-pushed the patapenka-alexey/tntp-4190-namer branch from a5ddaf9 to 955d2e8 Compare December 1, 2025 11:18
@oleg-jukovec oleg-jukovec removed their request for review December 1, 2025 11:30
@patapenka-alexey patapenka-alexey force-pushed the patapenka-alexey/tntp-4190-namer branch from 955d2e8 to 48ffc1c Compare December 1, 2025 11:52
@patapenka-alexey patapenka-alexey force-pushed the patapenka-alexey/tntp-4190-namer branch from 48ffc1c to 71fa8ac Compare December 1, 2025 12:09
return nil, fmt.Errorf("failed to sign: %w", err)
}

names := gv.Namer.GenerateNames(name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we generate names and then parse them with another method of the same class. At the moment it looks like we decode what we have just encoded. If it is the only planned usage of such classes I'd suggest to have a kind of single GenerateKeys method that generates keys from name instead of 2-phase transformation name->names->keys.

@bigbes
Copy link
Collaborator

bigbes commented Dec 1, 2025

Have a small discussion with @patapenka-alexey about how to reorganize package:

type key struct {
    name     string   // Object identifier
    type     KeyType  // Type of object (hash/signature/value)
    property string   // Additional metadata (version/algorithm)
    raw      string   // Raw key string
}
type Key interface {
    Name()     string   // Get object name
    Type()     KeyType  // Get key type
    Property() string   // Get metadata (e.g., algorithm version)
    Build()    string   // Reconstruct raw key string
}
type DefaultNamer struct {
    prefix string // Key prefix (e.g., "storage/")
}

// Constructor with hash/signature name configurations
func NewDefaultNamer(prefix string, hashNames, sigNames []string) *DefaultNamer

// Methods:
// - Generate all keys for an object name
func (n *DefaultNamer) GenerateNames(name string) []Key {}

// - Parse multiple raw keys into grouped results
func (n *DefaultNamer) ParseNamesMulti(names []string) ParseNamesResult {}
type ParseNamesResult struct {
    isSingle     bool           // True if result contains only one object name
    isSingleName string         // Cached name when isSingle=true
    result       map[string][]Key // Grouped keys: object name → key list
}

// Helper methods:
// - Get keys for single-name case (if applicable)
func (r *ParseNamesResult) SelectSingle() ([]Key, bool)

// - Iterate over all name→keys groups
func (r *ParseNamesResult) Iter() iter.Seq2[string, []Key]

// - Get keys for a specific object name
func (r *ParseNamesResult) Select(name string) ([]Key, bool)

// - Count unique object names
func (r *ParseNamesResult) Len() int

Signing/Generation Workflow

  1. Input: object name + value.
  2. Process:
    • Generate all keys via DefaultNamer.GenerateNames(name).
    • For each generated Key:
      • If KeyType = signature: generate cryptographic signature
      • If KeyType = hash: compute hash of value
      • If KeyType = value: marshal raw data
  3. Output: []KeyValue records.

Validation Workflow

  1. Input: []KeyValue records (optionally indexed via map[string]KeyValue).
  2. Process:
    • Parse all keys using DefaultNamer.ParseNamesMulti().
    • Group keys by original object name.
    • For each object name group:
      • Validate signatures/hashes using Key.Build() to reconstruct original keys
  3. Output: validated values (single or multiple objects).

This code decomposition and API will help us test code, will make clearer separation of "parsing/generation/validation" logic.

Note 1

SelectSingle might be unnecessary – consider replacing ParseNamesResult with map[string][]Key if single-name access isn't critical.

Note 2

Parsing logic centralized in keyFromString(key string) key, which:

  • Checks prefixes (e.g., strings.HasPrefix(key, "<prefix>/hash"))
  • Automatically infers key types and metadata

namer/namer.go Outdated
var key Key

// Remove prefix.
result := strings.ReplaceAll(name, n.prefix, "")
Copy link
Contributor

@elhimov elhimov Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will remove not only prefix, but all occurrences of n.prefix substring.
And what if name does not start with n.prefix?

Suggested change
result := strings.ReplaceAll(name, n.prefix, "")
result, found := strings.CutPrefix(name, n.prefix)
if !found {
continue // or something similar
}

@oleg-jukovec oleg-jukovec requested review from oleg-jukovec and removed request for oleg-jukovec December 4, 2025 08:11
@patapenka-alexey patapenka-alexey force-pushed the patapenka-alexey/tntp-4190-namer branch 3 times, most recently from b982e1d to 1dc942d Compare December 10, 2025 05:48
@patapenka-alexey patapenka-alexey force-pushed the patapenka-alexey/tntp-4190-namer branch from 05307e4 to 6f22bf6 Compare December 10, 2025 08:51
@patapenka-alexey patapenka-alexey marked this pull request as draft December 11, 2025 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants