From 9680b7251cd2be22caaed8f1468bd9e8915a62fb Mon Sep 17 00:00:00 2001 From: YOCKOW Date: Tue, 6 Oct 2020 18:22:50 +0900 Subject: [PATCH] Make `memset_s` consistent with Darwin. (#52) Resolves [issue#51](https://github.com/apple/swift-crypto/issues/51). In Swift 5.3, a warning is viewed on Linux because `memset_s` implemented in this module returns `Void`. This commit let the function return the same type with Darwin. --- Sources/Crypto/Util/BoringSSL/Zeroization_boring.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/Crypto/Util/BoringSSL/Zeroization_boring.swift b/Sources/Crypto/Util/BoringSSL/Zeroization_boring.swift index ffb59a37..746c5742 100644 --- a/Sources/Crypto/Util/BoringSSL/Zeroization_boring.swift +++ b/Sources/Crypto/Util/BoringSSL/Zeroization_boring.swift @@ -14,11 +14,15 @@ #if !(os(macOS) || os(iOS) || os(watchOS) || os(tvOS)) @_implementationOnly import CCryptoBoringSSL +typealias errno_t = CInt + // This is a Swift wrapper for the libc function that does not exist on Linux. We shim it via a call to OPENSSL_cleanse. // We have the same syntax, but mostly ignore it. -func memset_s(_ s: UnsafeMutableRawPointer!, _ smax: Int, _ byte: CInt, _ n: Int) { +@discardableResult +func memset_s(_ s: UnsafeMutableRawPointer!, _ smax: Int, _ byte: CInt, _ n: Int) -> errno_t { assert(smax == n, "memset_s invariant not met") assert(byte == 0, "memset_s used to not zero anything") CCryptoBoringSSL_OPENSSL_cleanse(s, smax) + return 0 } #endif