diff options
author | Bin Jin <bjin@ctrl-d.org> | 2017-03-12 17:48:20 +0800 |
---|---|---|
committer | Bin Jin <bjin@ctrl-d.org> | 2017-03-12 17:48:20 +0800 |
commit | a2a3e540f2d1a507b34eccae26de09066a2a12fa (patch) | |
tree | 1e336189acd095d761eaad252f18ee6e32b7216b /src/Network/WireGuard/Internal/Types.hs | |
download | wireguard-hs-a2a3e540f2d1a507b34eccae26de09066a2a12fa.tar.xz wireguard-hs-a2a3e540f2d1a507b34eccae26de09066a2a12fa.zip |
Initial commit
Diffstat (limited to 'src/Network/WireGuard/Internal/Types.hs')
-rw-r--r-- | src/Network/WireGuard/Internal/Types.hs | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/Network/WireGuard/Internal/Types.hs b/src/Network/WireGuard/Internal/Types.hs new file mode 100644 index 0000000..3409e2a --- /dev/null +++ b/src/Network/WireGuard/Internal/Types.hs @@ -0,0 +1,78 @@ +module Network.WireGuard.Internal.Types + ( Index + , Counter + , PeerId + , PublicKey + , PrivateKey + , KeyPair + , PresharedKey + , Time + , UdpPacket + , TunPacket + , EncryptedPayload + , AuthTag + , TAI64n + , SessionKey(..) + , WireGuardError(..) + , getPeerId + , farFuture + ) where + +import Control.Exception (Exception, SomeException) +import qualified Crypto.Noise.DH as DH +import Crypto.Noise.DH.Curve25519 (Curve25519) +import Data.ByteArray (ScrubbedBytes) +import qualified Data.ByteArray as BA +import qualified Data.ByteString as BS +import Foreign.C.Types (CTime (..)) +import Network.Socket (SockAddr) +import System.Posix.Types (EpochTime) + +import Data.Word + +type Index = Word32 +type Counter = Word64 +type PeerId = BS.ByteString + +type PublicKey = DH.PublicKey Curve25519 +type PrivateKey = DH.SecretKey Curve25519 +type KeyPair = DH.KeyPair Curve25519 +type PresharedKey = ScrubbedBytes + +type Time = EpochTime + +type UdpPacket = (BS.ByteString, SockAddr) +type TunPacket = ScrubbedBytes + +type EncryptedPayload = BS.ByteString +type AuthTag = BS.ByteString +type TAI64n = BS.ByteString + +data SessionKey = SessionKey + { sendKey :: !ScrubbedBytes + , recvKey :: !ScrubbedBytes + } + +data WireGuardError + = DecryptFailureError + | DestinationNotReachableError + | DeviceNotReadyError + | EndPointUnknownError + | HandshakeInitiationReplayError + | InvalidIPPacketError + | InvalidWGPacketError String + | NoiseError SomeException + | NonceReuseError + | OutdatedPacketError + | RemotePeerNotFoundError + | SourceAddrBlockedError + | UnknownIndexError + deriving (Show) + +instance Exception WireGuardError + +getPeerId :: PublicKey -> PeerId +getPeerId = BA.convert . DH.dhPubToBytes + +farFuture :: Time +farFuture = CTime maxBound |