Example #1
0
// EnumProviders returns slice of CryptoProvider structures, describing
// available CSPs.
func EnumProviders() ([]CryptoProvider, error) {
	var (
		slen C.DWORD
	)

	res := make([]CryptoProvider, 0)
	index := C.DWORD(0)

	for {
		var provType C.DWORD

		if C.CryptEnumProviders(index, nil, 0, &provType, nil, &slen) == 0 {
			break
		}
		buf := make([]byte, slen)
		// XXX: Some evil magic here
		if C.CryptEnumProviders(index, nil, 0, &provType, (*C.CHAR)(unsafe.Pointer(&buf[0])), &slen) == 0 {
			return res, getErr("Error during provider enumeration")
		} else {
			res = append(res, CryptoProvider{Name: string(buf), Type: ProvType(provType)})
		}
		index++
	}
	return res, nil
}
Example #2
0
// EnumProviders returns slice of CryptoProvider structures, describing
// available CSPs.
func EnumProviders() (res []CryptoProvider, err error) {
	var (
		slen, provType, index C.DWORD
	)

	res = make([]CryptoProvider, 0)

	for index = 0; C.CryptEnumProviders(index, nil, 0, &provType, nil, &slen) != 0; index++ {
		buf := make([]byte, slen)
		// XXX: Some evil magic here
		if C.CryptEnumProviders(index, nil, 0, &provType, (*C.CHAR)(unsafe.Pointer(&buf[0])), &slen) == 0 {
			err = getErr("Error during provider enumeration")
			return
		}
		res = append(res, CryptoProvider{Name: string(buf), Type: ProvType(provType)})
	}
	return
}