Skip to content

Commit

Permalink
Make ssl.verifyFlag non-optional (#15)
Browse files Browse the repository at this point in the history
Motivation:
`VerifyFlag` already has an enum case `.none`, which might be confused with `Optional.none`.

Modifications:
- Add `.default` case to `VerifyFlag` to represent user's intention to use DataStax driver's default
- Change `ssl.verifyFlag` to non-optional with default value `.default`

Resolves #13
  • Loading branch information
yim-lee authored Dec 21, 2022
1 parent 0538b3b commit 4150253
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions Sources/CassandraClient/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,15 @@ internal final class Cluster {
extension CassandraClient.Configuration {
public struct SSL {
public var trustedCertificates: [String]?
public var verifyFlag: VerifyFlag?
public var verifyFlag: VerifyFlag = .default
public var cert: String?
public var privateKey: (key: String, password: String)?

/// Verification performed on the peer's certificate.
public enum VerifyFlag {
/// Use DataStax driver's default, which is .peerCert
case `default`

/// No verification is performed
case none
/// Certificate is present and valid
Expand All @@ -354,18 +357,20 @@ extension CassandraClient.Configuration {
try sslContext.addTrustedCert(cert)
}
}
if let verifyFlag = self.verifyFlag {
switch verifyFlag {
case .none:
sslContext.setVerifyFlags(CASS_SSL_VERIFY_NONE)
case .peerCert:
sslContext.setVerifyFlags(CASS_SSL_VERIFY_PEER_CERT)
case .peerIdentity:
sslContext.setVerifyFlags(CASS_SSL_VERIFY_PEER_IDENTITY)
case .peerIdentityDNS:
sslContext.setVerifyFlags(CASS_SSL_VERIFY_PEER_IDENTITY_DNS)
}

switch self.verifyFlag {
case .none:
sslContext.setVerifyFlags(CASS_SSL_VERIFY_NONE)
case .peerCert:
sslContext.setVerifyFlags(CASS_SSL_VERIFY_PEER_CERT)
case .peerIdentity:
sslContext.setVerifyFlags(CASS_SSL_VERIFY_PEER_IDENTITY)
case .peerIdentityDNS:
sslContext.setVerifyFlags(CASS_SSL_VERIFY_PEER_IDENTITY_DNS)
case .default:
() // use DataStax driver's default
}

if let cert = self.cert {
try sslContext.setCert(cert)
}
Expand Down

0 comments on commit 4150253

Please sign in to comment.