Don't pass read-only bytes as mutable to BoringSSL (#129)

Motivation:

The BoringSSL version of `BIO_new_mem_buf` takes a const buffer but
we pass a mutable one.

Modifications:

Pass a const buffer.

Result:

Unsafe instead of Unsafe+Mutable.
This commit is contained in:
Kevin Sweeney authored and Cory Benfield committed 2019-08-12 16:42:17 +01:00
1 parent c8ac6c1f5a
commit f5dd7a60ff
3 files changed
+4 -4

No files matched your search

+2 -2
View File
@@ -89,7 +89,7 @@ public class NIOSSLCertificate {
/// DER format.
public convenience init(bytes: [UInt8], format: NIOSSLSerializationFormats) throws {
let ref = bytes.withUnsafeBytes { (ptr) -> UnsafeMutablePointer<X509>? in
let bio = CNIOBoringSSL_BIO_new_mem_buf(UnsafeMutableRawPointer(mutating: ptr.baseAddress!), CInt(ptr.count))!
let bio = CNIOBoringSSL_BIO_new_mem_buf(ptr.baseAddress, CInt(ptr.count))!
defer {
CNIOBoringSSL_BIO_free(bio)
@@ -220,7 +220,7 @@ extension NIOSSLCertificate {
}
return try bytes.withUnsafeBytes { (ptr) -> [NIOSSLCertificate] in
let bio = CNIOBoringSSL_BIO_new_mem_buf(UnsafeMutableRawPointer(mutating: ptr.baseAddress!), CInt(ptr.count))!
let bio = CNIOBoringSSL_BIO_new_mem_buf(ptr.baseAddress, CInt(ptr.count))!
defer {
CNIOBoringSSL_BIO_free(bio)
}
+1 -1
View File
@@ -94,7 +94,7 @@ public struct NIOSSLPKCS12Bundle {
guard boringSSLIsInitialized else { fatalError("Failed to initialize BoringSSL") }
let p12 = buffer.withUnsafeBytes { pointer -> OpaquePointer? in
let bio = CNIOBoringSSL_BIO_new_mem_buf(UnsafeMutableRawPointer(mutating: pointer.baseAddress), CInt(pointer.count))!
let bio = CNIOBoringSSL_BIO_new_mem_buf(pointer.baseAddress, CInt(pointer.count))!
defer {
CNIOBoringSSL_BIO_free(bio)
}
+1 -1
View File
@@ -166,7 +166,7 @@ public class NIOSSLPrivateKey {
/// A delegating initializer for `init(buffer:format:passphraseCallback)` and `init(buffer:format:)`.
private convenience init(bytes: [UInt8], format: NIOSSLSerializationFormats, callbackManager: CallbackManagerProtocol?) throws {
let ref = bytes.withUnsafeBytes { (ptr) -> UnsafeMutablePointer<EVP_PKEY>? in
let bio = CNIOBoringSSL_BIO_new_mem_buf(UnsafeMutableRawPointer(mutating: ptr.baseAddress!), CInt(ptr.count))!
let bio = CNIOBoringSSL_BIO_new_mem_buf(ptr.baseAddress!, CInt(ptr.count))!
defer {
CNIOBoringSSL_BIO_free(bio)
}