You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DateKeys/locator/internal_test.go

78 lines
2.2 KiB

Review fixes: author keys, the writer, the CLI, extensions and the locator Fixes of the review of the session of 1 and 2 October that the text of spec v0.11 already asks for: - authorkey: String and GoString hide the secret key, which only Secret returns; ParsePublic refuses a key that is not a point of the curve (ed25519strict.OnCurve, checked against the square root of testkit). - capsule: a typed nil in AuthorKey, CMSSigner or Sealer is an error, never a capsule without the signature or the seal that was asked for. A panic while evaluating the signature or the seal fails only that part, F1 or S2, not both. OpenOptions.Accept sees the verdicts before step 18 and can refuse to publish the files. - extension.CheckWrite, the rule of encoders of spec 72: the writers of capsules and .dkk files refuse datekeys.note and datekeys.capsule outside the arrays where they are registered, or with invalid data. - CLI: encrypt -sign shows the author key and the code of AUTHOR_MESSAGE before it signs (rule 20); decrypt -expect-author compares the key of an F4 and writes nothing unless it matches; decrypt notifies a public note that it does not show; the lines of the verdicts break at the last space that fits, each row after the first behind a mark, so that the terminal never breaks them; L is the payload, not the content. - locator: a reader rejects an address that breaks 44.1 and keeps the others; addresses refuse the special-purpose blocks of IANA, IPv6 outside 2000::/3, localhost and local names, characters outside RFC 3986, dot segments, and a CID that does not decode to version 1 and a multihash; ParseInfo checks that the locator is an age file with one tlock stanza for the round of its DateKey; Info.Extension reads what it writes; its errors carry no normative code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 days ago
package locator
import (
"strings"
"testing"
"g.activething.com/go/DateKeys/codec"
)
func small() *Locator {
return &Locator{Addresses: []Address{{URI: "https://ejemplo.org/b"}}, EnvelopeHeader: []byte("h\n"), RestSize: 1}
}
// Review: a reader rejects an address that breaks the rules of §44.1, not the
// locator, and uses the others; a writer never writes such an address.
func TestUsableAddresses(t *testing.T) {
l := small()
l.Addresses = append([]Address{{URI: "http://ejemplo.org/a"}}, l.Addresses...)
if _, err := l.Marshal(); err == nil {
t.Error("a writer wrote an http address")
}
b, err := l.marshal()
if err != nil {
t.Fatal(err)
}
back, err := Unmarshal(b)
if err != nil || len(back.Addresses) != 2 {
t.Fatalf("a locator with a rejected address: %v", err)
}
if u := back.Usable(); len(u) != 1 || u[0].URI != "https://ejemplo.org/b" {
t.Errorf("usable: %v", u)
}
}
// Review: the plaintext measures the least multiple of 4096 that key 6 can
// fill. A CBOR of 8192 bytes where 4096 suffice, valid in every other way, is
// not canonical.
func TestLeastMultiple(t *testing.T) {
l := small()
var base codec.Encoder
l.encode(&base, -1)
b0, err := base.Out()
if err != nil {
t.Fatal(err)
}
var e codec.Encoder
l.encode(&e, 2*Block-len(b0)-1-3)
b, err := e.Out()
if err != nil || len(b) != 2*Block {
t.Fatalf("%d bytes, %v", len(b), err)
}
if _, err := Unmarshal(b); err == nil || !strings.Contains(err.Error(), "least multiple") {
t.Errorf("two blocks where one suffices: %v", err)
}
if want, err := l.Marshal(); err != nil || len(want) != Block {
t.Errorf("%d bytes, %v", len(want), err)
}
}
// Review: the bases where no length of key 6 completes a multiple are those
// where the plaintext would need 0 to 2, 26 or 259 more bytes: key 6 takes at
// least 3, and the header of its byte string grows at 24 and 256 bytes.
func TestPaddingBoundaries(t *testing.T) {
for base := 1; base <= 3*Block; base++ {
got := PlaintextLength(base)
need := (Block - base%Block) % Block
want := base + need
switch need {
case 0:
case 1, 2, 26, 259:
want += Block
}
if got != want {
t.Fatalf("base %d: %d bytes, want %d", base, got, want)
}
}
}

Powered by TurnKey Linux.