gosrs

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

README

gosrs

gosrs - Sender Rewriting Scheme (SRS) library for Go

gosrs is an implementation of the Sender Rewriting Scheme (SRS) in Go, based on the original SRS paper, and taking inspiration from the srslib Python implementation.

Highlights:

  • No external dependencies
  • Implements the standard "Guarded" SRS scheme as described in the original SRS paper;
  • Simple to use and understand.

Installation

go get  "github.com/daliand/gosrs"

Example Usage

Basic usage

import "github.com/daliand/gosrs"

// Setup Package
srs, err := gosrs.GuardedScheme("MyVerySecretKey")
if err != nil {
    os.Panic(err.Error())
}

// Forward rewrite
fwdAddr := srs.Forward("bob@example.com", "forward.com")
fmt.Printf("SRS Forward address: %s", fwdAddr)


// Reverse revrite
revAddr := srs.Reverse(fwdAddr)
fmt.Printf("Reversed address: %s", revAddr)

License

Licensed under the Apache License, Version 2.0.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidSeparator          = errors.New("gosrs: Invalid SRS separator. Must be one of '=', '+', '-'. Default '='")
	ErrInvalidSRSAddress         = errors.New("gosrs: Not an SRS address")
	ErrInvalidHash               = errors.New("gosrs: Invalid hash")
	ErrInvalidTimestampCharacter = errors.New("gosrs: Invalid timestamp character")
	ErrTimestampExpired          = errors.New("gosrs: Timestamp expired")
	ErrInvalidAddress            = errors.New("gosrs: Invalid email address")
)

Functions

This section is empty.

Types

type GS

type GS struct {
	// contains filtered or unexported fields
}

GS - Guarded Scheme Config struct

func GuardedScheme

func GuardedScheme(secret string) (*GS, error)

GuardedScheme initializes the library

func (*GS) Forward

func (GS *GS) Forward(from string, alias string) (string, error)

Forward - Rewrites sender 'from' address to 'alias' domain. As described in the SRS specification, the algorithm is:

  • If 'from' is an SRS1 address rewritten by 1stHop.com to SRS0 and later by nthHop.com to SRS1, rewrite to a new SRS1 address such that bounces will go to us then 1stHop.com.
  • If 'from' is an SRS0 address rewritten by 1stHop.com, rewrite to an SRS1 address such that bounces will go to us then back to 1stHop.com.
  • If 'from' is neither an SRS0 address nor an SRS1 address, rewrite to an SRS0 address such that bounces will go to us then back to 'from'.

func (*GS) Reverse

func (GS *GS) Reverse(addr string) (string, error)

Reverse reverses a rewritten address. As described in the SRS specification, the algorithm is:

  • If 'addr' is an SRS0 address rewritten by us, bounce to the original envelope sender address.
  • If 'addr' is an SRS1 address rewritten by 1stHop.com and then us, bounce to the SRS0 address rewritten by 1stHop.com.

func (*GS) SetHashlen

func (GS *GS) SetHashlen(len int) error

SetHashlen sets the length of the GS hash part

func (*GS) SetSeparator

func (GS *GS) SetSeparator(separator string) error

SetSeparator Sets the GS address separator to 'separator'. Must be one of '=', '+', or '-'

func (*GS) SetValidity

func (GS *GS) SetValidity(validity int64) error

SetValidity sets the number of days GS timstamp is valid for

Jump to

Keyboard shortcuts

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