/* Decode a binary key from Z85 printable text See: http://api.zeromq.org/4-1:zmq-z85-decode */ func Z85decode(s string) string { l1 := len(s) if l1%5 != 0 { panic("Z85decode: Length of Z85 string not a multiple of 5") } l2 := 4 * l1 / 5 dest := make([]byte, l2) cs := C.CString(s) defer C.free(unsafe.Pointer(cs)) C.zmq_z85_decode((*C.uint8_t)(&dest[0]), cs) return string(dest) }
func z85Validate(z85 string) bool { var decoded []C.uint8_t if len(z85)%5 != 0 { return false } else { // Avoid literal floats decoded = make([]C.uint8_t, 8*len(z85)/10) } // Grab a CString of the z85 we need to decode c_z85 := C.CString(z85) defer C.free(unsafe.Pointer(c_z85)) // Because gozmq does not yet expose this for us, we have to expose it ourselves if ret := C.zmq_z85_decode(&decoded[0], c_z85); ret == nil { return false } return true }