iso8583

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Fixed     = "fixed"
	Variable  = "variable"
	Bitmapped = "bitmap"
)
View Source
const (
	// IsoMessageType is a constant that indicates the Message Type or the MTI
	// (This name has special meaning within the context of ISO8583 and cannot be named anything else. The same restrictions apply for 'Bitmap')
	IsoMessageType = "Message Type"
	IsoBitmap      = "Bitmap"
)
View Source
const (
	FixedType     FieldType = "Fixed"
	VariableType  FieldType = "Variable"
	BitmappedType FieldType = "Bitmapped"

	ASCII  Encoding = "ASCII"
	EBCDIC Encoding = "EBCDIC"
	BINARY Encoding = "BINARY"
	BCD    Encoding = "BCD"

	ContentTypeAny = "Any"

	// Mli2I is a message length indicator that is 2 bytes binary that includes the length of indicator itself
	Mli2I = "2I"
	// Mli2E is 2 bytes binary with length of the indicator not included
	Mli2E = "2E"
)
View Source
const (
	ISO0      PinFormat = "ISO0"
	ISO1      PinFormat = "ISO1"
	ISO3      PinFormat = "ISO3"
	IBM3264   PinFormat = "IBM3264"
	ANSIX9_19 MacAlgo   = "ANSIX9_19"
)
View Source
const HighBitMask = uint64(1) << 63

Variables

View Source
var ErrInsufficientData = errors.New("isosim: Insufficient data to parse field")

ErrInsufficientData is an error when there is not enough data in the raw message to parse it

View Source
var ErrInvalidEncoding = errors.New("isosim: Invalid encoding")

ErrInvalidEncoding is when an unsupported encoding is used for a field

View Source
var ErrLargeLengthIndicator = errors.New("isosim: Too large length indicator size. ")

ErrLargeLengthIndicator is an error that could happen when a large lenght indicator is used in a variable field

View Source
var ErrUnknownField = errors.New("isosim: Unknown field")

ErrUnknownField is an error when a unknown field is referenced

View Source
var ErrUnreadDataRemaining = errors.New("isosim: Unprocessed data remaining")

ErrUnreadDataRemaining to represent a condition where data remain post parsing

View Source
var NumericRegexPattern = regexp.MustCompile("^[0-9]+$")

Functions

func NextBytes

func NextBytes(buf *bytes.Buffer, n int) ([]byte, error)

NextBytes returns the next 'n' bytes from the Buffer

func ReadSpecs

func ReadSpecs(specDir string) error

ReadSpecs initializes the spec defined in the file specDefFile

Types

type Assembler added in v2.0.1

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

Assembler defines a ISO8583 message assembler

func NewAssembler added in v2.0.1

func NewAssembler(assemblerCfg *AssemblerConfig) *Assembler

NewAssembler creates a new assembler

func (*Assembler) Assemble added in v2.0.1

func (asm *Assembler) Assemble(iso *Iso) ([]byte, *MetaInfo, error)

type AssemblerConfig added in v2.0.1

type AssemblerConfig struct {
	LogEnabled bool
}

AssemblerConfig defines all configuration options for the assembler

type Bitmap

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

Bitmap represents a bitmap in the ISO8583 specification

func NewBitmap

func NewBitmap() *Bitmap

NewBitmap creates a new empty bitmap

func (*Bitmap) BinaryString

func (bmp *Bitmap) BinaryString() string

BinaryString returns a binary string representing the Bitmap

func (*Bitmap) Bytes

func (bmp *Bitmap) Bytes() []byte

Bytes returns the bitmap as a slice of bytes

func (*Bitmap) Copy

func (bmp *Bitmap) Copy() *Bitmap

Copy returns a copy of the Bitmap

func (*Bitmap) Get

func (bmp *Bitmap) Get(pos int) *FieldData

Get returns the field-data for the field at position 'pos'

func (*Bitmap) IsOn

func (bmp *Bitmap) IsOn(position int) bool

IsOn returns a boolean to indicate if the field at position is set or not

func (*Bitmap) Set

func (bmp *Bitmap) Set(pos int, val string) error

Set sets a value for a field at position 'pos'

func (*Bitmap) SetOff

func (bmp *Bitmap) SetOff(position int)

SetOff sets the position offl̥

func (*Bitmap) SetOn

func (bmp *Bitmap) SetOn(position int)

SetOn sets the position on

type Encoding

type Encoding string

func (Encoding) AsString

func (e Encoding) AsString() string

func (Encoding) EncodeToString

func (e Encoding) EncodeToString(data []byte) string

type EnumValue

type EnumValue struct {
	Value       string `yaml:"value"`
	Description string `yaml:"description"`
}

EnumValue is an entry for hint type "enumerated"

type Field

type Field struct {
	Name                      string    `yaml:"name"`
	ID                        int       `yaml:"id"`
	Type                      FieldType `yaml:"type"`
	Size                      int       `yaml:"size"`
	Position                  int       `yaml:"position"`
	DataEncoding              Encoding  `yaml:"data_encoding"`
	LengthIndicatorSize       int       `yaml:"length_indicator_size"`
	LengthIndicatorMultiplier int       `yaml:"length_indicator_multiplier"`
	LengthIndicatorEncoding   Encoding  `yaml:"length_indicator_encoding"`

	Constraints FieldConstraints `yaml:"constraints"`
	Padding     PaddingType      `yaml:"padding"`

	Children []*Field `yaml:"children"`

	ParentId           int
	ValueGeneratorType string       `yaml:"gen_type"`
	PinGenProps        *PinGenProps `yaml:"pin_gen_props,omitempty"`
	MacGenProps        *MacGenProps `yaml:"mac_gen_props,omitempty"`

	Key  bool `yaml:"key"`
	Hint Hint `yaml:"hint"`
	// contains filtered or unexported fields
}

Field represents a field in the ISO message

func NewField

func NewField(info []string) (*Field, error)

NewField is a constructor for Field

func (*Field) GetChildren

func (f *Field) GetChildren() []*Field

Children returns a []Field of its children

func (*Field) HasChildren

func (f *Field) HasChildren() bool

HasChildren returns a boolean that indicates if the field has children (nested fields)

func (*Field) String

func (f *Field) String() string

String returns the attributes of the Field as a string

func (*Field) ValueFromString

func (f *Field) ValueFromString(data string) ([]byte, error)

ValueFromString constructs the value for a field from a raw form

func (*Field) ValueToString

func (f *Field) ValueToString(data []byte) string

ValueToString returns the value of the field to a string representation

type FieldConstraints

type FieldConstraints struct {
	ContentType string `yaml:"string"`
	MaxSize     int    `yaml:"max_size"`
	MinSize     int    `yaml:"min_size"`
}

type FieldData

type FieldData struct {
	Field *Field
	Data  []byte

	// Bitmap is only used for bitmapped fields to keep track of
	// what bits are on
	Bitmap *Bitmap
}

FieldData represents the data associated with a field in a ISO message

func (*FieldData) Copy

func (fd *FieldData) Copy() *FieldData

Copy returns a deep copy of FieldData

func (*FieldData) Set

func (fd *FieldData) Set(value string) error

Set sets the value for the field

func (*FieldData) Value

func (fd *FieldData) Value() string

Value returns the value of this field as a string

type FieldType

type FieldType string

type Hint

type Hint struct {

	//Type is the type of hint - date_time, currency_code and others
	Type string `yaml:"type"`
	//Format is an optional qualifier to add more context to the hint
	Format string `yaml:"format"`
	//Enumerated values are a array of values for enumerated hint type
	Values []EnumValue `yaml:"values"`
}

Hint represents metadata associated with a field that could be useful for the UI to aid the user to provide value for the field

type HintType

type HintType string

HintType is the type of hint

const (
	HintDateTime     HintType = "date_time"
	HintCurrencyCode HintType = "currency_code"
)

type Iso

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

Iso is a handle into accessing the details of a ISO message(via the parsedMsg)

func FromParsedMsg

func FromParsedMsg(parsedMsg *ParsedMsg) *Iso

FromParsedMsg constructs a new Iso from a parsedMsg

func (*Iso) Assemble

func (iso *Iso) Assemble() ([]byte, *MetaInfo, error)

Assemble assembles the raw form of the message

func (*Iso) Bitmap

func (iso *Iso) Bitmap() *Bitmap

Bitmap returns the Bitmap from the Iso message

func (*Iso) Get

func (iso *Iso) Get(fieldName string) *FieldData

Get returns a field by its name

func (*Iso) ParsedMsg

func (iso *Iso) ParsedMsg() *ParsedMsg

ParsedMsg returns the backing parsedMsg

func (*Iso) Set

func (iso *Iso) Set(fieldName string, value string) error

Set sets a field to the supplied value

type MacAlgo

type MacAlgo string

type MacGenProps

type MacGenProps struct {
	MacAlgo MacAlgo `yaml:"mac_algo",json:"mac_algo"`
	MacKey  string  `yaml:"mac_key",json:"mac_key"`
}

type Message

type Message struct {
	Name   string   `yaml:"name"`
	ID     int      `yaml:"id"`
	Fields []*Field `yaml:"fields"`
	// HeaderMatch
	HeaderMatch []string `yaml:"header_match"`
	// contains filtered or unexported fields
}

Message represents a message within a specification (auth/reversal etc)

func (*Message) AllFields

func (msg *Message) AllFields() []*Field

Fields returns all fields of this Message

func (*Message) Field

func (msg *Message) Field(fieldName string) *Field

Field returns a field by its name

func (*Message) FieldById

func (msg *Message) FieldById(id int) *Field

FieldById returns a field by its id

func (*Message) NewIso

func (msg *Message) NewIso() *Iso

NewIso returns a Iso instance that can be used to build messages

func (*Message) Parse

func (msg *Message) Parse(msgData []byte) (*ParsedMsg, error)

Parse parses a a byte slice representing the message into fields

func (*Message) ParseJSON

func (msg *Message) ParseJSON(jsonMsg string) (*ParsedMsg, error)

ParseJSON parses a JSON list of field values (from UI) into a parsed message representation

type MetaInfo

type MetaInfo struct {
	// OpTime is time taken by an operation
	OpTime time.Duration
	// MessageKey is a key that can be used to uniquely identify a transaction
	MessageKey string
}

MetaInfo provides additional information about an operation performed For example, in response to a parse or assemble op

type PaddingType

type PaddingType string
const (
	LeadingZeroes PaddingType = "LEADING_ZEROES"
	LeadingSpaces PaddingType = "LEADING_SPACES"
	LeadingF      PaddingType = "LEADING_F"

	TrailingZeroes PaddingType = "TRAILING_ZEROES"
	TrailingSpaces PaddingType = "TRAILING_SPACES"
	TrailingF      PaddingType = "TRAILING_F"
)

type ParsedMsg

type ParsedMsg struct {
	IsRequest bool
	Msg       *Message

	//A map of Id to FieldData
	FieldDataMap map[int]*FieldData

	// MessageKey is a value that unique identifies a transaction
	// (usually a combination of fields like STAN, PAN etc)
	MessageKey string
}

ParsedMsg is a type that represents a parsed form of a ISO8583 message

func (*ParsedMsg) Copy

func (pMsg *ParsedMsg) Copy() *ParsedMsg

Copy returns a deep copy of the ParsedMsg

func (*ParsedMsg) Get

func (pMsg *ParsedMsg) Get(name string) *FieldData

Get returns the field-data from the parsed message given its name

func (*ParsedMsg) GetById

func (pMsg *ParsedMsg) GetById(id int) *FieldData

GetById returns field data given its id

type Parser added in v2.0.1

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

Parser defines a ISO8583 message parser

func NewParser added in v2.0.1

func NewParser(parserCfg *ParserConfig) *Parser

NewParser creates and returns a new parser

func (*Parser) Parse added in v2.0.1

func (p *Parser) Parse(msg *Message, msgData []byte) (*ParsedMsg, *MetaInfo, error)

Parse parses msgData to the structure defined by msg

type ParserConfig added in v2.0.1

type ParserConfig struct {
	LogEnabled bool
}

ParserConfig defines the various configurations of the Parser

type PinFormat

type PinFormat string

type PinGenProps

type PinGenProps struct {
	PINClear         string    `yaml:"pin_clear",json:"pin_clear"`
	PINFormat        PinFormat `yaml:"pin_format",json:"pin_format"`
	PINKey           string    `yaml:"pin_key",json:"pin_key"`
	PANFieldID       int       `yaml:"pan_field_id",json:"pan_field_id"`
	PANExtractParams string    `yaml:"pan_extract_params",json:"pan_extract_params"`
	PAN              string    `yaml:"pan",json:"pan"`
}

func (*PinGenProps) Generate

func (pgp *PinGenProps) Generate() ([]byte, error)

type Spec

type Spec struct {
	Name string `yaml:"name"`
	ID   int    `yaml:"id"`

	HeaderFields []*Field `yaml:"header_fields"`

	Messages []*Message `yaml:"messages"`
}

Spec represents an ISO8583 specification

func AllSpecs

func AllSpecs() []*Spec

AllSpecs returns a list of all defined specs

func SpecByID

func SpecByID(specId int) *Spec

SpecByID returns a spec given it's id

func SpecByName

func SpecByName(specName string) *Spec

SpecByName returns a spec given its name

func (*Spec) FindTargetMsg

func (spec *Spec) FindTargetMsg(data []byte) *Message

FindTargetMsg parses any defined header fields and returns a message

func (*Spec) GetMessages

func (spec *Spec) GetMessages() []*Message

Messages returns a list of all messages defined for the spec

func (*Spec) GetOrAddMsg

func (spec *Spec) GetOrAddMsg(msgId int, msgName string) (*Message, bool)

GetOrAddMsg returns (or adds and returns) a msg - This is usually called during initialization

func (*Spec) MessageByID

func (spec *Spec) MessageByID(msgId int) *Message

MessageByID returns a message given its id

func (*Spec) MessageByName

func (spec *Spec) MessageByName(msgName string) *Message

MessageByName returns a message given its name

type Specs

type Specs struct {
	Specs []Spec `yaml:"specs"`
}

Jump to

Keyboard shortcuts

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