hwormhole-0.2.0.0: magic-wormhole client

Safe HaskellNone
LanguageHaskell2010

Transit.Internal.Crypto

Description

 
Synopsis

Documentation

encrypt :: Key -> Nonce -> PlainText -> Either CryptoError CipherText Source #

encrypt the given chunk with the given secretbox key and nonce. Saltine's nonce seem represented as a big endian bytestring. However, to interop with the wormhole python client, we need to use and send nonce as a little endian bytestring.

decrypt :: Key -> CipherText -> Either CryptoError (PlainText, Nonce) Source #

decrypt the bytestring representing ciphertext block with the given key. It is assumed that the ciphertext bytestring is nonce followed by the actual encrypted data.

newtype PlainText Source #

Type for representing unencrypted plain text

Constructors

PlainText ByteString 
Instances
Eq PlainText Source # 
Instance details

Defined in Transit.Internal.Crypto

Methods

(==) :: PlainText -> PlainText -> Bool

(/=) :: PlainText -> PlainText -> Bool

Show PlainText Source # 
Instance details

Defined in Transit.Internal.Crypto

Methods

showsPrec :: Int -> PlainText -> ShowS

show :: PlainText -> String

showList :: [PlainText] -> ShowS

newtype CipherText Source #

Type for representing encrypted cipher text.

Constructors

CipherText ByteString 
Instances
Eq CipherText Source # 
Instance details

Defined in Transit.Internal.Crypto

Methods

(==) :: CipherText -> CipherText -> Bool

(/=) :: CipherText -> CipherText -> Bool

deriveKeyFromPurpose :: Purpose -> Key -> ByteString Source #

derive a new purpose-specific key from a master key.

data Purpose Source #

Various purpose types for key derivation.

Normally used with deriveKeyFromPurpose.

Constructors

SenderHandshake

Purpose type to be used by transit sender.

ReceiverHandshake

Purpose type to be used by transit receiver.

SenderRecord

Purpose type to be used for encrypting records.

ReceiverRecord

Purpose type to be used for decrypting records.

RelayHandshake

Purpose type to be used for transit relay handshake.

Instances
Eq Purpose Source # 
Instance details

Defined in Transit.Internal.Crypto

Methods

(==) :: Purpose -> Purpose -> Bool

(/=) :: Purpose -> Purpose -> Bool

Show Purpose Source # 
Instance details

Defined in Transit.Internal.Crypto

Methods

showsPrec :: Int -> Purpose -> ShowS

show :: Purpose -> String

showList :: [Purpose] -> ShowS

data CryptoError Source #

Error Type for exceptions thrown by the Crypto module

Constructors

BadNonce Text

The nonce value in the received message is invalid.

CouldNotDecrypt Text

We could not decrypt the incoming encrypted record.

KeyGenError Text

Could not generate transit keys.

Instances
Eq CryptoError Source # 
Instance details

Defined in Transit.Internal.Crypto

Methods

(==) :: CryptoError -> CryptoError -> Bool

(/=) :: CryptoError -> CryptoError -> Bool

Show CryptoError Source # 
Instance details

Defined in Transit.Internal.Crypto

Methods

showsPrec :: Int -> CryptoError -> ShowS

show :: CryptoError -> String

showList :: [CryptoError] -> ShowS

Exception CryptoError Source # 
Instance details

Defined in Transit.Internal.Crypto

Methods

toException :: CryptoError -> SomeException

fromException :: SomeException -> Maybe CryptoError

displayException :: CryptoError -> String