gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet-go-plugins] 01/03: records: changed record layout (LSD0002).


From: gnunet
Subject: [gnunet-go-plugins] 01/03: records: changed record layout (LSD0002).
Date: Fri, 11 Nov 2022 11:59:23 +0100

This is an automated email from the git hooks/post-receive script.

bernd-fix pushed a commit to branch master
in repository gnunet-go-plugins.

commit f1d132cd71067c59734fa3c7947b09aa179a64c2
Author: Bernd Fix <brf@hoi-polloi.org>
AuthorDate: Fri Nov 4 15:30:52 2022 +0100

    records: changed record layout (LSD0002).
---
 reclaimid/records.go | 53 ++++++++++++++++++++++++++++++----------------------
 1 file changed, 31 insertions(+), 22 deletions(-)

diff --git a/reclaimid/records.go b/reclaimid/records.go
index f08f04d..5e8a8d0 100644
--- a/reclaimid/records.go
+++ b/reclaimid/records.go
@@ -25,7 +25,6 @@ package main
 import (
        "bytes"
        "encoding/base32"
-       "encoding/hex"
        "fmt"
        "strconv"
        "strings"
@@ -69,23 +68,21 @@ func GetInstance(t uint32, buf []byte) (rec ReclaimRecord, 
err error) {
 
 // ReclaimAttribute record
 type ReclaimAttribute struct {
-       Type       uint32 `order:"big"`    // type
-       Flags      uint32 `order:"big"`    // claim
-       ID         []byte `size:"32"`      // Reclaim identifier
-       Credential []byte `size:"32"`      // Reclaim identifier
-       NameLen    uint16 `order:"big"`    // length of name
-       Res1       uint16 `order:"big"`    // reserved
-       DataLen    uint16 `order:"big"`    // length of data
-       Res2       uint16 `order:"big"`    // reserved
-       Name       []byte `size:"NameLen"` // name
-       Data       []byte `size:"DataLen"` // binary data
+       Type        uint32 `order:"big"`    // type
+       Flags       uint32 `order:"big"`    // claim
+       ID          []byte `size:"32"`      // Reclaim identifier
+       Attestation []byte `size:"32"`      // Attestation
+       NameLen     uint32 `order:"big"`    // length of name
+       DataLen     uint32 `order:"big"`    // length of data
+       Name        []byte `size:"NameLen"` // name
+       Data        []byte `size:"DataLen"` // binary data
 }
 
 // Value returns a human-readable representation of the record
 func (rec *ReclaimAttribute) Value(inv Utility) (string, error) {
        wrt := new(bytes.Buffer)
        wrt.WriteString(fmt.Sprintf("ID=%s,<br>", encodeBase32GNS(rec.ID)))
-       cred := encodeBase32GNS(rec.Credential)
+       cred := encodeBase32GNS(rec.Attestation)
        if len(strings.ReplaceAll(cred, "0", "")) > 0 {
                wrt.WriteString(fmt.Sprintf("Credential=%s,<br>", cred))
        }
@@ -110,7 +107,7 @@ func (rec *ReclaimAttribute) Value(inv Utility) (string, 
error) {
 func (rec *ReclaimAttribute) ToMap(inv Utility) (params map[string]string, err 
error) {
        params = make(map[string]string)
        params["reclaim_attribute_id"] = encodeBase32GNS(rec.ID)
-       params["reclaim_attribute_credential"] = encodeBase32GNS(rec.Credential)
+       params["reclaim_attribute_credential"] = 
encodeBase32GNS(rec.Attestation)
        params["reclaim_attribute_type"] = fmt.Sprintf("%d", rec.Type)
        params["reclaim_attribute_flags"] = fmt.Sprintf("%d", rec.Flags)
        params["reclaim_attribute_key"] = string(rec.Name)
@@ -132,10 +129,8 @@ type ReclaimCredential struct {
        Type    uint32 `order:"big"`    // credendial type
        Flags   uint32 `order:"big"`    // flags
        ID      []byte `size:"32"`      // credential ID
-       NameLen uint16 `order:"big"`    // length of name
-       Res1    uint16 `order:"big"`    // reserved
-       DataLen uint16 `order:"big"`    // length of data
-       Res2    uint16 `order:"big"`    // reserved
+       NameLen uint32 `order:"big"`    // length of name
+       DataLen uint32 `order:"big"`    // length of data
        Name    []byte `size:"NameLen"` // name
        Data    []byte `size:"DataLen"` // binary data
 }
@@ -144,11 +139,18 @@ type ReclaimCredential struct {
 func (rec *ReclaimCredential) Value(inv Utility) (string, error) {
        wrt := new(bytes.Buffer)
        wrt.WriteString(fmt.Sprintf("ID=%s,<br>", encodeBase32GNS(rec.ID)))
-       wrt.WriteString(fmt.Sprintf("Type=%d,<br>", rec.Type))
+       var ok bool
+       var rtype string
+       if inv != nil {
+               rtype, ok = inv("gns_type_name", rec.Type).(string)
+       }
+       if ok {
+               wrt.WriteString(fmt.Sprintf("Type=%s,<br>", rtype))
+       } else {
+               wrt.WriteString(fmt.Sprintf("Type=%d,<br>", rec.Type))
+       }
        wrt.WriteString(fmt.Sprintf("Flags=%d,<br>", rec.Flags))
-       name := string(rec.Name)
-       val := hex.EncodeToString(rec.Data)
-       wrt.WriteString(fmt.Sprintf("[%s=%s]", name, split(val, 64)))
+       wrt.WriteString(fmt.Sprintf("[%s=%s]", string(rec.Name), 
string(rec.Data)))
        return wrt.String(), nil
 }
 
@@ -159,7 +161,7 @@ func (rec *ReclaimCredential) ToMap(inv Utility) (params 
map[string]string, err
        params["reclaim_credential_type"] = fmt.Sprintf("%d", rec.Type)
        params["reclaim_credential_flags"] = fmt.Sprintf("%d", rec.Flags)
        params["reclaim_credential_key"] = string(rec.Name)
-       params["reclaim_credential_value"] = hex.EncodeToString(rec.Data)
+       params["reclaim_credential_value"] = string(rec.Data)
        return
 }
 
@@ -173,6 +175,8 @@ func (rec *ReclaimCredential) FromMap(inv Utility, params 
map[string]string) err
 //----------------------------------------------------------------------
 
 // Split a string into lines of given length
+//
+//nolint:deadcode // might be used, might be not...
 func split(s string, chunk int) string {
        out := ""
        for len(s) > chunk {
@@ -182,6 +186,7 @@ func split(s string, chunk int) string {
                out += s[:chunk]
                s = s[chunk:]
        }
+       out += s
        return out
 }
 
@@ -194,6 +199,8 @@ func encodeBase32GNS(buf []byte) string {
 }
 
 // Convert string to byte array using Base32GNS
+//
+//nolint:deadcode // might be used, might be not...
 func decodeBase32GNS(s string) ([]byte, error) {
        s = strings.ToUpper(s)
        s = strings.NewReplacer("O", "0", "I", "1", "L", "1", "U", 
"V").Replace(s)
@@ -206,6 +213,8 @@ type Number interface {
 }
 
 // convert parameter value (string) to given number type
+//
+//nolint:deadcode // might be used, might be not...
 func asInt[T Number](params map[string]string, key string) (val T, err error) {
        vs, ok := params[key]
        if !ok {

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]