gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet-go-plugins] branch master updated: Changed plugin interface; cu


From: gnunet
Subject: [gnunet-go-plugins] branch master updated: Changed plugin interface; custom record layout.
Date: Fri, 28 Oct 2022 18:55:45 +0200

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.

The following commit(s) were added to refs/heads/master by this push:
     new be2877b  Changed plugin interface; custom record layout.
be2877b is described below

commit be2877ba1161292c4f148c9b33d81af93b62da76
Author: Bernd Fix <brf@hoi-polloi.org>
AuthorDate: Fri Oct 28 18:54:51 2022 +0200

    Changed plugin interface; custom record layout.
---
 go.mod               |  2 ++
 go.sum               | 14 ++++++++
 reclaimid/Makefile   |  2 +-
 reclaimid/main.go    | 58 ++++++++++++++++++--------------
 reclaimid/rrtypes.go | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 144 insertions(+), 26 deletions(-)

diff --git a/go.mod b/go.mod
index dbcb388..0c68c9e 100644
--- a/go.mod
+++ b/go.mod
@@ -1,3 +1,5 @@
 module plugins
 
 go 1.19
+
+require github.com/bfix/gospel v1.2.21
diff --git a/go.sum b/go.sum
index e69de29..23b15e6 100644
--- a/go.sum
+++ b/go.sum
@@ -0,0 +1,14 @@
+github.com/bfix/gospel v1.2.21 h1:rgllMlR+2AZt6+x0uaBF67a+pM7fJxHiO93amhKXZNU=
+github.com/bfix/gospel v1.2.21/go.mod 
h1:cdu63bA9ZdfeDoqZ+vnWOcbY9Puwdzmf5DMxMGMznRI=
+github.com/huin/goupnp v1.0.0/go.mod 
h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc=
+github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod 
h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod 
h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod 
h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
+golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod 
h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod 
h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod 
h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod 
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod 
h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod 
h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
diff --git a/reclaimid/Makefile b/reclaimid/Makefile
index acd9ae1..4b04dc6 100644
--- a/reclaimid/Makefile
+++ b/reclaimid/Makefile
@@ -27,4 +27,4 @@ clean: ${GOPATH}/bin/plugin_reclaimid.so
        rm -f $^
 
 ${GOPATH}/bin/plugin_reclaimid.so: main.go gui.htpl
-       go build -buildmode=plugin -gcflags="-N -l" -o $@ ./...
+       go build -buildmode=plugin -trimpath -gcflags="-N -l" -o $@ ./...
diff --git a/reclaimid/main.go b/reclaimid/main.go
index f42aa22..b8e5ad7 100644
--- a/reclaimid/main.go
+++ b/reclaimid/main.go
@@ -24,19 +24,19 @@ package main
 
 import (
        _ "embed"
+
+       "github.com/bfix/gospel/data"
 )
 
-// List of handled resource record types with associated identifier.
-// The identifiers MUST be derived from stripped enums.GNSType strings
-// and must be used as template names.
-var handledTypes = map[uint32]string{
-       65544: "RECLAIM_ATTRIBUTE",
-       65545: "RECLAIM_TICKET",
-       65550: "RECLAIM_ATTRIBUTE_REF",
-       65552: "RECLAIM_OIDC_CLIENT",
-       65553: "RECLAIM_OIDC_REDIRECT",
-       65554: "RECLAIM_CREDENTIAL",
-       65555: "RECLAIM_PRESENTATION",
+// List of handled resource record types.
+var handledTypes = []uint32{
+       65544, // RECLAIM_ATTRIBUTE
+       65545, // RECLAIM_TICKET
+       65550, // RECLAIM_ATTRIBUTE_REF
+       65552, // RECLAIM_OIDC_CLIENT
+       65553, // RECLAIM_OIDC_REDIRECT
+       65554, // RECLAIM_CREDENTIAL
+       65555, // RECLAIM_PRESENTATION
 }
 
 // Plugin is the instance of a custom implementation accessed by the
@@ -66,10 +66,7 @@ func (p *ReclaimIDPlugin) Name() string {
 // CanHandle returns a list of resource record types that are handled by the
 // plugin
 func (p *ReclaimIDPlugin) CanHandle() (list []uint32) {
-       for t := range handledTypes {
-               list = append(list, t)
-       }
-       return
+       return handledTypes
 }
 
 //go:embed gui.htpl
@@ -87,20 +84,31 @@ func (p *ReclaimIDPlugin) TemplateNames() (string, string) {
 }
 
 // Value returns a human-readable description of RR data
-func (p *ReclaimIDPlugin) Value(t uint32, rr []byte) string {
-       return "(not handled yet)"
+func (p *ReclaimIDPlugin) Value(t uint32, rr []byte) (string, error) {
+       rec, err := GetInstance(t, rr)
+       if err != nil {
+               return "", err
+       }
+       return rec.Value()
 }
 
 // ToMap converts resource record data into GUI template variables
-func (p *ReclaimIDPlugin) ToMap(t uint32, rr []byte) map[string]string {
-       return make(map[string]string)
+func (p *ReclaimIDPlugin) ToMap(t uint32, rr []byte) (map[string]string, 
error) {
+       rec, err := GetInstance(t, rr)
+       if err != nil {
+               return nil, err
+       }
+       return rec.ToMap()
 }
 
 // FromMap converts a GUI template variables into resource record data
-func (p *ReclaimIDPlugin) FromMap(t uint32, vars map[string]string) []byte {
-       return make([]byte, 0)
+func (p *ReclaimIDPlugin) FromMap(t uint32, vars map[string]string) ([]byte, 
error) {
+       rec, err := GetInstance(t, nil)
+       if err != nil {
+               return nil, err
+       }
+       if err = rec.FromMap(vars); err != nil {
+               return nil, err
+       }
+       return data.Marshal(rec)
 }
-
-//----------------------------------------------------------------------
-// helper functions
-//----------------------------------------------------------------------
diff --git a/reclaimid/rrtypes.go b/reclaimid/rrtypes.go
new file mode 100644
index 0000000..7a92254
--- /dev/null
+++ b/reclaimid/rrtypes.go
@@ -0,0 +1,94 @@
+// This file is part of gnunet-go-plugins, a collection of plugins for
+// the GNUnet-implementation in Golang (gnunet.go). Plugins are used to
+// implement type-specific processing of resource records (e.g. GUI).
+// Copyright (C) 2022 by the authors:
+//
+// * Bernd Fix <brf@hoi-polloi.org>  >Y<
+//
+// gnunet-go-plugins is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published
+// by the Free Software Foundation, either version 3 of the License,
+// or (at your option) any later version.
+//
+// gnunet-go is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+// SPDX-License-Identifier: AGPL3.0-or-later
+
+package main
+
+import (
+       "errors"
+
+       "github.com/bfix/gospel/data"
+)
+
+// ReclaimRecord interface impemented by custom types.
+type ReclaimRecord interface {
+       Value() (string, error)
+       ToMap() (map[string]string, error)
+       FromMap(map[string]string) error
+}
+
+// Get record instance for given type and data
+func GetInstance(t uint32, buf []byte) (rec ReclaimRecord, err error) {
+       switch t {
+       case 65544: // RECLAIM_ATTRIBUTE
+               rec = new(ReclaimAttribute)
+       case 65545: // RECLAIM_TICKET
+       case 65550: // RECLAIM_ATTRIBUTE_REF
+       case 65552: // RECLAIM_OIDC_CLIENT
+       case 65553: // RECLAIM_OIDC_REDIRECT
+       case 65554: // RECLAIM_CREDENTIAL
+       case 65555: // RECLAIM_PRESENTATION
+       }
+       if buf != nil {
+               err = data.Unmarshal(rec, buf)
+       }
+       return
+}
+
+//======================================================================
+// Reclaim Resource Records
+//======================================================================
+
+//----------------------------------------------------------------------
+// Reclaim Attribute
+//----------------------------------------------------------------------
+
+// ReclaimAttribute record
+type ReclaimAttribute struct {
+       ID         []byte `size:"32"`      // Reclaim identifier
+       Credential []byte `size:"32"`      // Reclaim identifier
+       Claim      uint32 `order:"big"`    // claim
+       Type       uint32 `order:"big"`    // type
+       Flags      uint32 `order:"big"`    // flags
+       Name       string ``               // name
+       LenData    uint16 `order:"big"`    // length of data
+       Data       []byte `size:"LenData"` // binary data
+}
+
+// Value returns a human-readable representation of the record
+func (rec *ReclaimAttribute) Value() (string, error) {
+       return "", errors.New("not implemented yet")
+}
+
+// ToMap returns the parameter set for the record
+func (rec *ReclaimAttribute) ToMap() (params map[string]string, err error) {
+       params = make(map[string]string)
+       return
+}
+
+// FromMap reconstructs the record attributes from parameter list
+func (rec *ReclaimAttribute) FromMap(params map[string]string) error {
+       return nil
+}
+
+//----------------------------------------------------------------------
+// Reclaim ...
+//----------------------------------------------------------------------

-- 
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]