Convert ct pulling to try/catch

This commit is contained in:
Davide De Rosa 2018-10-23 22:37:29 +02:00
parent bbaa60c3bd
commit f725779e0e
1 changed files with 17 additions and 4 deletions

View File

@ -614,7 +614,10 @@ public class SessionProxy {
return
}
guard let cipherTextOut = try? negotiationKey.tls.pullCipherText() else {
let cipherTextOut: Data
do {
cipherTextOut = try negotiationKey.tls.pullCipherText()
} catch {
log.verbose("TLS.auth: Still can't pull ciphertext")
return
}
@ -637,7 +640,10 @@ public class SessionProxy {
log.debug("TLS.ifconfig: Put plaintext (PUSH_REQUEST)")
try? negotiationKey.tls.putPlainText("PUSH_REQUEST\0")
guard let cipherTextOut = try? negotiationKey.tls.pullCipherText() else {
let cipherTextOut: Data
do {
cipherTextOut = try negotiationKey.tls.pullCipherText()
} catch {
log.verbose("TLS.ifconfig: Still can't pull ciphertext")
return
}
@ -717,7 +723,10 @@ public class SessionProxy {
return
}
guard let cipherTextOut = try? negotiationKey.tls.pullCipherText() else {
let cipherTextOut: Data
do {
cipherTextOut = try negotiationKey.tls.pullCipherText()
} catch {
deferStop(.shutdown, SessionError.tlsError)
return
}
@ -745,9 +754,13 @@ public class SessionProxy {
log.debug("TLS.connect: Put received ciphertext (\(cipherTextIn.count) bytes)")
try? negotiationKey.tls.putCipherText(cipherTextIn)
if let cipherTextOut = try? negotiationKey.tls.pullCipherText() {
let cipherTextOut: Data
do {
cipherTextOut = try negotiationKey.tls.pullCipherText()
log.debug("TLS.connect: Send pulled ciphertext (\(cipherTextOut.count) bytes)")
enqueueControlPackets(code: .controlV1, key: negotiationKey.id, payload: cipherTextOut)
} catch {
log.verbose("TLS.connect: No available ciphertext to pull")
}
if negotiationKey.shouldOnTLSConnect() {