예제 #1
0
func TestEncodeBitsMasksExcess(t *testing.T) {
	for _, tc := range []bitTestCase{
		{0, []byte{255, 255}, ""},
		{1, []byte{255, 255}, "o"},
		{2, []byte{255, 255}, "a"},
		{3, []byte{255, 255}, "h"},
		{4, []byte{255, 255}, "6"},
		{5, []byte{255, 255}, "9"},
		{6, []byte{255, 255}, "9o"},
		{7, []byte{255, 255}, "9a"},
		{8, []byte{255, 255}, "9h"},
		{9, []byte{255, 255}, "96"},
		{10, []byte{255, 255}, "99"},
		{11, []byte{255, 255}, "99o"},
		{12, []byte{255, 255}, "99a"},
		{13, []byte{255, 255}, "99h"},
		{14, []byte{255, 255}, "996"},
		{15, []byte{255, 255}, "999"},
		{16, []byte{255, 255}, "999o"},
	} {
		dst := make([]byte, zbase32.EncodedLen(len(tc.decoded)))
		n := zbase32.EncodeBits(dst, tc.decoded, tc.bits)
		dst = dst[:n]
		if g, e := string(dst), tc.encoded; g != e {
			t.Errorf("EncodeBits %d bits of %x wrong result: %q != %q", tc.bits, tc.decoded, g, e)
		}
	}
}
예제 #2
0
func TestEncodeBits(t *testing.T) {
	for _, tc := range bitTests {
		dst := make([]byte, zbase32.EncodedLen(len(tc.decoded)))
		n := zbase32.EncodeBits(dst, tc.decoded, tc.bits)
		dst = dst[:n]
		if g, e := string(dst), tc.encoded; g != e {
			t.Errorf("EncodeBits %d bits of %x wrong result: %q != %q", tc.bits, tc.decoded, g, e)
			continue
		}
	}
}
예제 #3
0
func main() {
	log.SetFlags(0)
	log.SetPrefix(prog + ": ")

	flag.Usage = usage
	flag.Parse()

	if flag.NArg() != 0 {
		usage()
		os.Exit(1)
	}

	data, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		log.Fatal(err)
	}
	encoded := make([]byte, zbase32.EncodedLen(len(data)))
	n := zbase32.Encode(encoded, data)
	encoded = encoded[:n]
	encoded = append(encoded, '\n')
	if _, err := os.Stdout.Write(encoded); err != nil {
		log.Fatal(err)
	}
}