Skip to content

Commit

Permalink
skip tests not supported by SymCrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
qmuntal committed Sep 4, 2024
1 parent 2ae7b98 commit 2d7482d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions export_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
package openssl

import "sync"

var ErrOpen = errOpen

var SymCryptProviderAvailable = sync.OnceValue(func() bool {
return isProviderAvailable("symcryptprovider")
})
8 changes: 8 additions & 0 deletions openssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ func FIPS() bool {
}
}

// isProviderAvailable checks if the provider with the given name is available.
// This function is used in export_test.go, as test files can't access C functions.
func isProviderAvailable(name string) bool {
providerName := C.CString(name)
defer C.free(unsafe.Pointer(providerName))
return C.go_openssl_OSSL_PROVIDER_available(nil, providerName) == 1
}

// SetFIPS enables or disables FIPS mode.
//
// For OpenSSL 3, the `fips` provider is loaded if enabled is true,
Expand Down
8 changes: 8 additions & 0 deletions rsa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func TestEncryptDecryptOAEP_EmptyLabel(t *testing.T) {
}

func TestEncryptDecryptOAEP_WithMGF1Hash(t *testing.T) {
if openssl.SymCryptProviderAvailable() {
t.Skip("SymCrypt provider does not support MGF1 hash")
}

sha1 := openssl.NewSHA1()
sha256 := openssl.NewSHA256()
msg := []byte("hi!")
Expand Down Expand Up @@ -148,6 +152,10 @@ func TestSignVerifyPKCS1v15(t *testing.T) {
}

func TestSignVerifyPKCS1v15_Unhashed(t *testing.T) {
if openssl.SymCryptProviderAvailable() {
t.Skip("SymCrypt provider does not support unhashed PKCS1v15")
}

msg := []byte("hi!")
priv, pub := newRSAKey(t, 2048)
signed, err := openssl.SignRSAPKCS1v15(priv, 0, msg)
Expand Down

0 comments on commit 2d7482d

Please sign in to comment.