Ejemplo n.º 1
0
func (m *M) Final() string {
	re := (*_Ctype_unsignedchar)(C.malloc(16))
	C.MD5_Final(re, m.ctx)
	dst := fmt.Sprintf("%02X", C.GoBytes(unsafe.Pointer(re), 16))
	C.free(unsafe.Pointer(re))
	return dst
}
Ejemplo n.º 2
0
func (ctx *MD5Context) Final() ([]byte, error) {
	res := make([]byte, C.MD5_DIGEST_LENGTH)
	ret := C.MD5_Final((*C.uchar)(unsafe.Pointer(&res[0])), (*C.MD5_CTX)(ctx))
	if ret == 0 {
		return res, errors.New("Error during MD5 finalize")
	}

	return res, nil
}
Ejemplo n.º 3
0
func (d *digest) Sum(in []byte) []byte {
	context := *d.context
	defer func() { *d.context = context }()

	md := make([]byte, Size)
	if C.MD5_Final((*_Ctype_unsignedchar)(&md[0]), d.context) == 1 {
		return append(in, md...)
	}

	return nil
}
Ejemplo n.º 4
0
Archivo: md5.go Proyecto: runcom/gossl
func (d *digest) Sum(b []byte) []byte {
	buf := make([]C.uchar, d.Size())
	// make a copy of the pointer, so our context does not get freed.
	// this allows further writes.
	// TODO perhaps we should think about runtime.SetFinalizer to free the context?
	ctxTmp := C.MD5_CTX(d.ctx)
	if C.MD5_Final(&buf[0], &ctxTmp) != 1 {
		return make([]byte, 0)
	}
	var result []byte
	if b != nil {
		result = make([]byte, 0)
	} else {
		result = b
	}
	for _, value := range buf {
		result = append(result, byte(value))
	}
	return result
}
Ejemplo n.º 5
0
func (mh *MD5Hash) Sum(b []byte) []byte {
	digest := make([]C.uchar, mh.Size())
	// make a copy of the pointer, so our context does not get freed.
	// this allows further writes.
	// TODO perhaps we should think about runtime.SetFinalizer to free the context?
	s_tmp := C.MD5_CTX(mh.md5)
	if C.MD5_Final(&digest[0], &s_tmp) != 1 {
		// TODO maybe not panic here?
		panic("couldn't finalize digest")
	}
	var result []byte
	if b != nil {
		result = make([]byte, 0)
	} else {
		result = b
	}
	for _, value := range digest {
		result = append(result, byte(value))
	}
	return result
}