switch base64 to raw
This commit is contained in:
@@ -24,6 +24,8 @@ content:\n // literally this word on one line *directly* after the newline of th
|
|||||||
|
|
||||||
The canonical form is exactly this, except for the signature and following linebreak, hashed with Blake2b.
|
The canonical form is exactly this, except for the signature and following linebreak, hashed with Blake2b.
|
||||||
|
|
||||||
|
The binary data - Event Ids, Pubkeys and Signatures are encoded in raw base64 URL encoding (without padding), Signatures are 86 characters, Ids and Pubkeys are 43 characters long.
|
||||||
|
|
||||||
The database stored form of this event should make use of an event ID hash to monotonic collision free serial table and an event table.
|
The database stored form of this event should make use of an event ID hash to monotonic collision free serial table and an event table.
|
||||||
|
|
||||||
Event ID hashes will be encoded in URL-base64 where used in tags or mentioned in content with the prefix `e:`. Public keys must be prefixed with `p:` Tag keys should be intelligible words and a specification for their structure should be defined by users of them and shared with other REALY devs.
|
Event ID hashes will be encoded in URL-base64 where used in tags or mentioned in content with the prefix `e:`. Public keys must be prefixed with `p:` Tag keys should be intelligible words and a specification for their structure should be defined by users of them and shared with other REALY devs.
|
||||||
|
|||||||
@@ -2,13 +2,15 @@ package event
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"protocol.realy.lol/pkg/event/types"
|
"protocol.realy.lol/pkg/event/types"
|
||||||
|
"protocol.realy.lol/pkg/pubkey"
|
||||||
|
"protocol.realy.lol/pkg/signature"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Event struct {
|
type Event struct {
|
||||||
Type types.T
|
Type types.T
|
||||||
Pubkey []byte
|
Pubkey pubkey.P
|
||||||
Timestamp int64
|
Timestamp int64
|
||||||
Tags [][]byte
|
Tags [][]byte
|
||||||
Content []byte
|
Content []byte
|
||||||
Signature []byte
|
Signature signature.S
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Len = 44
|
const Len = 43
|
||||||
|
|
||||||
type P struct{ ed25519.PublicKey }
|
type P struct{ ed25519.PublicKey }
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ func (p *P) Marshal(dst []byte) (result []byte, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
buf := bytes.NewBuffer(result)
|
buf := bytes.NewBuffer(result)
|
||||||
w := base64.NewEncoder(base64.URLEncoding, buf)
|
w := base64.NewEncoder(base64.RawURLEncoding, buf)
|
||||||
if _, err = w.Write(p.PublicKey); chk.E(err) {
|
if _, err = w.Write(p.PublicKey); chk.E(err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@ func (p *P) Unmarshal(data []byte) (rem []byte, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
p.PublicKey = make([]byte, ed25519.PublicKeySize)
|
p.PublicKey = make([]byte, ed25519.PublicKeySize)
|
||||||
if _, err = base64.URLEncoding.Decode(p.PublicKey, rem[:i]); chk.E(err) {
|
if _, err = base64.RawURLEncoding.Decode(p.PublicKey, rem[:i]); chk.E(err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rem = rem[i+1:]
|
rem = rem[i+1:]
|
||||||
|
|||||||
@@ -8,31 +8,33 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestP_Marshal_Unmarshal(t *testing.T) {
|
func TestP_Marshal_Unmarshal(t *testing.T) {
|
||||||
pk := make([]byte, ed25519.PublicKeySize)
|
|
||||||
var err error
|
var err error
|
||||||
if _, err = rand.Read(pk); chk.E(err) {
|
for range 10 {
|
||||||
t.Fatal(err)
|
pk := make([]byte, ed25519.PublicKeySize)
|
||||||
}
|
if _, err = rand.Read(pk); chk.E(err) {
|
||||||
log.I.S(pk)
|
t.Fatal(err)
|
||||||
var p *P
|
}
|
||||||
if p, err = New(pk); chk.E(err) {
|
log.I.S(pk)
|
||||||
t.Fatal(err)
|
var p *P
|
||||||
}
|
if p, err = New(pk); chk.E(err) {
|
||||||
var o []byte
|
t.Fatal(err)
|
||||||
if o, err = p.Marshal(nil); chk.E(err) {
|
}
|
||||||
t.Fatal(err)
|
var o []byte
|
||||||
}
|
if o, err = p.Marshal(nil); chk.E(err) {
|
||||||
log.I.F("%d %s", len(o), o)
|
t.Fatal(err)
|
||||||
p2 := &P{}
|
}
|
||||||
var rem []byte
|
log.I.F("%d %s", len(o), o)
|
||||||
if rem, err = p2.Unmarshal(o); chk.E(err) {
|
p2 := &P{}
|
||||||
t.Fatal(err)
|
var rem []byte
|
||||||
}
|
if rem, err = p2.Unmarshal(o); chk.E(err) {
|
||||||
if len(rem) > 0 {
|
t.Fatal(err)
|
||||||
log.I.F("%d %s", len(rem), rem)
|
}
|
||||||
}
|
if len(rem) > 0 {
|
||||||
log.I.S(p2.PublicKey)
|
log.I.F("%d %s", len(rem), rem)
|
||||||
if !bytes.Equal(pk, p2.PublicKey) {
|
}
|
||||||
t.Fatal("public key did not encode/decode faithfully")
|
log.I.S(p2.PublicKey)
|
||||||
|
if !bytes.Equal(pk, p2.PublicKey) {
|
||||||
|
t.Fatal("public key did not encode/decode faithfully")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Len = 88
|
const Len = 86
|
||||||
|
|
||||||
type S struct{ Signature []byte }
|
type S struct{ Signature []byte }
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ func (p *S) Marshal(dst []byte) (result []byte, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
buf := bytes.NewBuffer(result)
|
buf := bytes.NewBuffer(result)
|
||||||
w := base64.NewEncoder(base64.URLEncoding, buf)
|
w := base64.NewEncoder(base64.RawURLEncoding, buf)
|
||||||
if _, err = w.Write(p.Signature); chk.E(err) {
|
if _, err = w.Write(p.Signature); chk.E(err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@ func (p *S) Unmarshal(data []byte) (rem []byte, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
p.Signature = make([]byte, ed25519.SignatureSize)
|
p.Signature = make([]byte, ed25519.SignatureSize)
|
||||||
if _, err = base64.URLEncoding.Decode(p.Signature, rem[:i]); chk.E(err) {
|
if _, err = base64.RawURLEncoding.Decode(p.Signature, rem[:i]); chk.E(err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rem = rem[i+1:]
|
rem = rem[i+1:]
|
||||||
|
|||||||
@@ -8,31 +8,34 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestS_Marshal_Unmarshal(t *testing.T) {
|
func TestS_Marshal_Unmarshal(t *testing.T) {
|
||||||
sig := make([]byte, ed25519.SignatureSize)
|
|
||||||
var err error
|
var err error
|
||||||
if _, err = rand.Read(sig); chk.E(err) {
|
for range 10 {
|
||||||
t.Fatal(err)
|
sig := make([]byte, ed25519.SignatureSize)
|
||||||
}
|
if _, err = rand.Read(sig); chk.E(err) {
|
||||||
log.I.S(sig)
|
t.Fatal(err)
|
||||||
var s *S
|
}
|
||||||
if s, err = New(sig); chk.E(err) {
|
log.I.S(sig)
|
||||||
t.Fatal(err)
|
var s *S
|
||||||
}
|
if s, err = New(sig); chk.E(err) {
|
||||||
var o []byte
|
t.Fatal(err)
|
||||||
if o, err = s.Marshal(nil); chk.E(err) {
|
}
|
||||||
t.Fatal(err)
|
var o []byte
|
||||||
}
|
if o, err = s.Marshal(nil); chk.E(err) {
|
||||||
log.I.F("%d %s", len(o), o)
|
t.Fatal(err)
|
||||||
p2 := &S{}
|
}
|
||||||
var rem []byte
|
log.I.F("%d %s", len(o), o)
|
||||||
if rem, err = p2.Unmarshal(o); chk.E(err) {
|
p2 := &S{}
|
||||||
t.Fatal(err)
|
var rem []byte
|
||||||
}
|
if rem, err = p2.Unmarshal(o); chk.E(err) {
|
||||||
if len(rem) > 0 {
|
t.Fatal(err)
|
||||||
log.I.F("%d %s", len(rem), rem)
|
}
|
||||||
}
|
if len(rem) > 0 {
|
||||||
log.I.S(p2.Signature)
|
log.I.F("%d %s", len(rem), rem)
|
||||||
if !bytes.Equal(sig, p2.Signature) {
|
}
|
||||||
t.Fatal("signature did not encode/decode faithfully")
|
log.I.S(p2.Signature)
|
||||||
|
if !bytes.Equal(sig, p2.Signature) {
|
||||||
|
t.Fatal("signature did not encode/decode faithfully")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user