stringprep

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2018 License: Apache-2.0 Imports: 3 Imported by: 60

README

GoDoc Build Status

stringprep – Go implementation of RFC-3454 stringprep and RFC-4013 SASLprep

Synopsis

    import "github.com/xdg/stringprep"

    prepped := stringprep.SASLprep.Prepare("TrustNô1")

Description

This library provides an implementation of the stringprep algorithm (RFC-3454) in Go, including all data tables.

A pre-built SASLprep (RFC-4013) profile is provided as well.

Copyright 2018 by David A. Golden. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"). You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Documentation

Overview

Package stringprep provides data tables and algorithms for RFC-3454, including errata (as of 2018-02). It also provides a profile for SASLprep as defined in RFC-4013.

Example (CustomProfile)
package main

import (
	"fmt"

	"github.com/xdg/stringprep"
)

func main() {
	customProfile := stringprep.Profile{
		Mappings: []stringprep.Mapping{
			stringprep.TableB1,
			stringprep.TableB2,
		},
		Normalize: true,
		Prohibits: []stringprep.Set{
			stringprep.TableC1_1,
			stringprep.TableC1_2,
		},
		CheckBiDi: true,
	}

	prepped, err := customProfile.Prepare("TrustNô1")
	if err != nil {
		panic("stringprep failed")
	}

	fmt.Print(prepped)
}
Output:

trustnô1
Example (SASLprep)
package main

import (
	"fmt"

	"github.com/xdg/stringprep"
)

func main() {
	prepped, err := stringprep.SASLprep.Prepare("TrustNô1")
	if err != nil {
		panic("SASLprep failed")
	}
	fmt.Print(prepped)
}
Output:

TrustNô1

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Msg  string
	Rune rune
}

Error describes problems encountered during stringprep, including what rune was problematic.

func (Error) Error

func (e Error) Error() string

type Mapping

type Mapping map[rune][]rune

Mapping represents a stringprep mapping, from a single rune to zero or more runes.

var TableB1 Mapping = tableB1

TableB1 represents RFC-3454 Table B.1.

var TableB2 Mapping = tableB2

TableB2 represents RFC-3454 Table B.2.

var TableB3 Mapping = tableB3

TableB3 represents RFC-3454 Table B.3.

func (Mapping) Map

func (m Mapping) Map(r rune) (replacement []rune, ok bool)

Map maps a rune to a (possibly empty) rune slice via a stringprep Mapping. The ok return value is false if the rune was not found.

type Profile

type Profile struct {
	Mappings  []Mapping
	Normalize bool
	Prohibits []Set
	CheckBiDi bool
}

Profile represents a stringprep profile.

var SASLprep Profile = saslprep

SASLprep is a pre-defined stringprep profile for user names and passwords as described in RFC-4013.

Because the stringprep distinction between query and stored strings was intended for compatibility across profile versions, but SASLprep was never updated and is now deprecated, this profile only operates in stored strings mode, prohibiting unassigned code points.

func (Profile) Prepare

func (p Profile) Prepare(s string) (string, error)

Prepare transforms an input string to an output string following the rules defined in the profile as defined by RFC-3454.

type RuneRange

type RuneRange [2]rune

RuneRange represents a close-ended range of runes: [N,M]. For a range consisting of a single rune, N and M will be equal.

func (RuneRange) Contains

func (rr RuneRange) Contains(r rune) bool

Contains returns true if a rune is within the bounds of the RuneRange.

type Set

type Set []RuneRange

Set represents a stringprep data table used to identify runes of a particular type.

var TableA1 Set = tableA1

TableA1 represents RFC-3454 Table A.1.

var TableC1_1 Set = tableC1_1

TableC1_1 represents RFC-3454 Table C.1.1.

var TableC1_2 Set = tableC1_2

TableC1_2 represents RFC-3454 Table C.1.2.

var TableC2_1 Set = tableC2_1

TableC2_1 represents RFC-3454 Table C.2.1.

var TableC2_2 Set = tableC2_2

TableC2_2 represents RFC-3454 Table C.2.2.

var TableC3 Set = tableC3

TableC3 represents RFC-3454 Table C.3.

var TableC4 Set = tableC4

TableC4 represents RFC-3454 Table C.4.

var TableC5 Set = tableC5

TableC5 represents RFC-3454 Table C.5.

var TableC6 Set = tableC6

TableC6 represents RFC-3454 Table C.6.

var TableC7 Set = tableC7

TableC7 represents RFC-3454 Table C.7.

var TableC8 Set = tableC8

TableC8 represents RFC-3454 Table C.8.

var TableC9 Set = tableC9

TableC9 represents RFC-3454 Table C.9.

var TableD1 Set = tableD1

TableD1 represents RFC-3454 Table D.1.

var TableD2 Set = tableD2

TableD2 represents RFC-3454 Table D.2.

func (Set) Contains

func (s Set) Contains(r rune) bool

Contains returns true if a rune is within any of the RuneRanges in the Set.

Jump to

Keyboard shortcuts

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