md5

package
v6.3.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

README

md5

Provides a integrity check transfer filter

Usage

import "github.com/henrylee2cn/erpc/v6/xfer/md5"

Test
package md5_test

import (
	"testing"
	"time"

	"github.com/henrylee2cn/erpc/v6"
	"github.com/henrylee2cn/erpc/v6/xfer"
	"github.com/henrylee2cn/erpc/v6/xfer/md5"
)

func TestSeparate(t *testing.T) {
	// Register filter(custom)
	md5.Reg('m', "md5")
	md5Check, _ := xfer.Get('m')
	input := []byte("md5")
	b, err := md5Check.OnPack(input)
	if err != nil {
		t.Fatalf("Onpack: %v", err)
	}

	_, err = md5Check.OnUnpack(b)
	if err != nil {
		t.Fatalf("Md5 check failed: %v", err)
	}

	// Tamper with data
	b = append(b, "viruses"...)
	_, err = md5Check.OnUnpack(b)
	if err == nil {
		t.Fatal("Md5 check failed:")
	}
}

func TestCombined(t *testing.T) {
	// Register filter(custom)
	md5.Reg('m', "md5")
	// Server
	srv := erpc.NewPeer(erpc.PeerConfig{ListenPort: 9090})
	srv.RouteCall(new(Home))
	go srv.ListenAndServe()
	time.Sleep(1e9)

	// Client
	cli := erpc.NewPeer(erpc.PeerConfig{})
	sess, stat := cli.Dial(":9090")
	if !stat.OK() {
		t.Fatal(stat)
	}
	var result interface{}
	stat = sess.Call("/home/test",
		map[string]interface{}{
			"bytes": "test bytes",
		},
		&result,
		// Use custom filter
		erpc.WithXferPipe('m'),
	).Status()
	if !stat.OK() {
		t.Error(stat)
	}
	t.Logf("result:%v", result)
}

type Home struct {
	erpc.CallCtx
}

func (h *Home) Test(arg *map[string]interface{}) (map[string]interface{}, *erpc.Status) {
	return map[string]interface{}{
		"result": "your request is:" + (*arg)["bytes"].(string),
	}, nil
}

test command:

# Separate test
go test -v -run=TestSeparate
# Combined with erpc test
go test -v -run=TestCombined

Documentation

Overview

Package md5 provides a integrity check transfer filter

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Reg

func Reg(id byte, name string)

Reg registers a md5 checker filter for transfer.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL