Source File
base32.go
Belonging Package
encoding/base32
package base32
import (
)
var StdEncoding = NewEncoding(encodeStd)
var HexEncoding = NewEncoding(encodeHex)
switch len() {
default:
[7] = [4] & 0x1F
[6] = [4] >> 5
fallthrough
case 4:
[6] |= ([3] << 3) & 0x1F
[5] = ([3] >> 2) & 0x1F
[4] = [3] >> 7
fallthrough
case 3:
[4] |= ([2] << 1) & 0x1F
[3] = ([2] >> 4) & 0x1F
fallthrough
case 2:
[3] |= ([1] << 4) & 0x1F
[2] = ([1] >> 1) & 0x1F
[1] = ([1] >> 6) & 0x1F
fallthrough
case 1:
[1] |= ([0] << 2) & 0x1F
[0] = [0] >> 3
}
:= len()
func ( *Encoding) ( []byte) string {
:= make([]byte, .EncodedLen(len()))
.Encode(, )
return string()
}
type encoder struct {
err error
enc *Encoding
w io.Writer
buf [5]byte // buffered data waiting to be encoded
nbuf int // number of bytes in buf
out [1024]byte // output buffer
}
func ( *encoder) ( []byte) ( int, error) {
if .err != nil {
return 0, .err
}
type CorruptInputError int64
func ( CorruptInputError) () string {
return "illegal base32 data at input byte " + strconv.FormatInt(int64(), 10)
}
return , false, CorruptInputError( - len() - )
, = , true
break
}
:= [0]
= [1:]
return , false, CorruptInputError()
}
for := 0; < 8-1-; ++ {
return , false, CorruptInputError( - len() + - 1)
}
}
if == 1 || == 3 || == 6 {
return , false, CorruptInputError( - len() - 1)
}
break
}
[] = .decodeMap[]
if [] == 0xFF {
return , false, CorruptInputError( - len() - 1)
}
++
}
switch {
case 8:
[+4] = [6]<<5 | [7]
++
fallthrough
case 7:
[+3] = [4]<<7 | [5]<<2 | [6]>>3
++
fallthrough
case 5:
[+2] = [3]<<4 | [4]>>1
++
fallthrough
case 4:
[+1] = [1]<<6 | [2]<<1 | [3]>>4
++
fallthrough
case 2:
[+0] = [0]<<3 | [1]>>2
++
}
+= 5
}
return , , nil
}
func ( *Encoding) ( string) ([]byte, error) {
:= []byte()
:= stripNewlines(, )
, , := .decode(, [:])
return [:],
}
type decoder struct {
err error
enc *Encoding
r io.Reader
end bool // saw end of message
buf [1024]byte // leftover input
nbuf int
out []byte // leftover decoded output
outbuf [1024 / 8 * 5]byte
}
func ( io.Reader, []byte, int, bool) ( int, error) {
for < && == nil {
var int
, = .Read([:])
+=
if < && > 0 && == io.EOF {
= io.ErrUnexpectedEOF
if && < 8 && == 0 && == io.EOF {
= io.ErrUnexpectedEOF
}
return
}
var int
if .enc.padChar == NoPadding {
= .nbuf
} else {
= .nbuf / 8 * 8
}
:= .enc.DecodedLen(.nbuf)
if > len() {
, .end, = .enc.decode(.outbuf[0:], .buf[0:])
.out = .outbuf[0:]
= copy(, .out)
.out = .out[:]
} else {
, .end, = .enc.decode(, .buf[0:])
}
.nbuf -=
for := 0; < .nbuf; ++ {
.buf[] = .buf[+]
}
if != nil && (.err == nil || .err == io.EOF) {
.err =
}
func (, []byte) int {
:= 0
for , := range {
if == '\r' || == '\n' {
continue
}
[] =
++
}
return
}
func ( *newlineFilteringReader) ( []byte) (int, error) {
, := .wrapped.Read()
for > 0 {
:= [0:]
:= stripNewlines(, )
if != nil || > 0 {
return ,
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |