 //
 // Created by Raimundas Sakalauskas on 21/08/2018.
-// Copyright (c) 2018 spark. All rights reserved.
+// Maintained by Raimundas Sakalauskas
+// Copyright (c) 2018 Particle. All rights reserved.
 //
 
 import Foundation
 import mbedTLSWrapper
 
 protocol MeshSetupBluetoothConnectionHandshakeManagerDelegate {
-    func handshakeDidFail(sender: MeshSetupBluetoothConnectionHandshakeManager, error: HanshakeManagerError)
+    func handshakeDidFail(sender: MeshSetupBluetoothConnectionHandshakeManager, error: HandshakeManagerError, severity: MeshSetupErrorSeverity)
     func handshakeDidSucceed(sender: MeshSetupBluetoothConnectionHandshakeManager, derivedSecret: Data)
 }
 
-enum HanshakeManagerError: Error {
+enum HandshakeManagerError: Error, CustomStringConvertible {
     case FailedToInitializeEcJPake
     case FailedToCreateRoundOne
     case FailedToCreateRoundTwo

            handshakeState = .roundTwoSent
            deriveSecret()
        } else {
            handshakeState = .failed
            self.delegate?.handshakeDidFail(sender: self, error: .FailedToCreateRoundTwo)
        }
    }


            handshakeState = .roundOneRead
            //server will respond with data for roundTwoRead
        } else {
            fail(withReason: .FailedToReadRoundOne)
        }
    }

    private func readRoundTwo(_ data: Data) {
        log("Handshake: readRoundTwo")
        let result = ecJPakeWrapper.readRoundTwo(data)

        if (result == 0) {
