Skip to content

Commit c50e935

Browse files
qmuntalkariannadagood
authored
Skip tests not supported by SymCrypt (#164)
* skip tests not supported by SymCrypt * SymCryptProviderAvailable should always return false in OpenSSL 1 * Update openssl.go fuller explanation Co-authored-by: Davis Goodin <[email protected]> --------- Co-authored-by: Martijn Verburg <[email protected]> Co-authored-by: Davis Goodin <[email protected]>
1 parent 0c798b7 commit c50e935

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

export_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
package openssl
22

3+
import "sync"
4+
35
var ErrOpen = errOpen
6+
7+
var SymCryptProviderAvailable = sync.OnceValue(func() bool {
8+
if vMajor == 1 {
9+
return false
10+
}
11+
return isProviderAvailable("symcryptprovider")
12+
})

openssl.go

+8
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ func FIPS() bool {
111111
}
112112
}
113113

114+
// isProviderAvailable checks if the provider with the given name is available.
115+
// This function is used in export_test.go, but must be defined here as test files can't access C functions.
116+
func isProviderAvailable(name string) bool {
117+
providerName := C.CString(name)
118+
defer C.free(unsafe.Pointer(providerName))
119+
return C.go_openssl_OSSL_PROVIDER_available(nil, providerName) == 1
120+
}
121+
114122
// SetFIPS enables or disables FIPS mode.
115123
//
116124
// For OpenSSL 3, the `fips` provider is loaded if enabled is true,

rsa_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ func TestEncryptDecryptOAEP_EmptyLabel(t *testing.T) {
8181
}
8282

8383
func TestEncryptDecryptOAEP_WithMGF1Hash(t *testing.T) {
84+
if openssl.SymCryptProviderAvailable() {
85+
t.Skip("SymCrypt provider does not support MGF1 hash")
86+
}
87+
8488
sha1 := openssl.NewSHA1()
8589
sha256 := openssl.NewSHA256()
8690
msg := []byte("hi!")
@@ -148,6 +152,10 @@ func TestSignVerifyPKCS1v15(t *testing.T) {
148152
}
149153

150154
func TestSignVerifyPKCS1v15_Unhashed(t *testing.T) {
155+
if openssl.SymCryptProviderAvailable() {
156+
t.Skip("SymCrypt provider does not support unhashed PKCS1v15")
157+
}
158+
151159
msg := []byte("hi!")
152160
priv, pub := newRSAKey(t, 2048)
153161
signed, err := openssl.SignRSAPKCS1v15(priv, 0, msg)

0 commit comments

Comments
 (0)