summaryrefslogtreecommitdiffhomepage
path: root/Types.hs
blob: 7262f336f337857cc27b2c528d7b87745dc2105f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{-# LANGUAGE OverloadedStrings, GeneralizedNewtypeDeriving, MultiParamTypeClasses, FlexibleInstances #-}

module Types where

import Types.Cost
import Entropy
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
import Data.String

-- | keysafe stores secret keys.
newtype SecretKey = SecretKey B.ByteString

-- | The secret key, encrypted with a password.
data EncryptedSecretKey = EncryptedSecretKey B.ByteString (CostCalc BruteForceOp UnknownPassword)

instance Bruteforceable EncryptedSecretKey UnknownPassword where
	getBruteCostCalc (EncryptedSecretKey _ cc) = cc

-- | Objects stored on a keysafe server are (probably) a shard of an
-- encrypted secret key.
newtype StorableObject = StorableObject { fromStorableObject :: BL.ByteString }

-- | A password used to encrypt a key stored in keysafe.
newtype Password = Password B.ByteString
	deriving (IsString)

-- | Naive calculation of the entropy of a password.
-- Does not take common passwords and password generation patterns into
-- account, so this is an overestimation of how hard a password
-- is to crack.
passwordEntropy :: Password -> Entropy UnknownPassword
passwordEntropy (Password p) = Entropy $ floor $ totalEntropy p

-- | A name associated with a key stored in keysafe.
newtype Name = Name B.ByteString
	deriving (Show)

-- | The type of the key that is stored in keysafe.
newtype KeyType = KeyType B.ByteString
	deriving (Show)

gpgKey :: KeyType
gpgKey = KeyType "gpg"

-- | Enough information to uniquely identify a key stored in keysafe.
data KeyIdent = KeyIdent KeyType Name
	deriving (Show)

newtype ShardNum = ShardNum Int
	deriving (Show)

-- | Enough information to uniquely identify an object stored on a keysafe
-- server for a key.
data ObjectIdent = ObjectIdent ShardNum KeyIdent
	deriving (Show)

data Benchmark t = Benchmark { expectedBenchmark :: t, actualBenchmark :: t }
	deriving (Show)