summaryrefslogtreecommitdiffhomepage
path: root/Types.hs
blob: d3eeccbe1cbd8a9f050f60740f63b5cb7a1586b6 (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
60
61
{-# LANGUAGE OverloadedStrings, GeneralizedNewtypeDeriving, MultiParamTypeClasses, FlexibleInstances #-}

{- Copyright 2016 Joey Hess <id@joeyh.name>
 -
 - Licensed under the GNU AGPL version 3 or higher.
 -}

module Types where

import Types.Cost
import qualified Data.ByteString as B
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 Show EncryptedSecretKey where
	show (EncryptedSecretKey b _) = show b

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 :: B.ByteString }
	deriving (Show)

-- | An identifier for a StorableObject
newtype StorableObjectIdent = StorableObjectIdent B.ByteString
	deriving (Show)

-- | A shard, with a known number (N of M).
data Shard = Shard ShardNum StorableObject

type ShardNum = Int

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

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

-- | Source of the secret key stored in keysafe.
data SecretKeySource = GpgKey KeyId | KeyFile FilePath
	deriving (Show)

-- | The keyid is any value that is unique to a private key, and can be
-- looked up somehow without knowing the private key.
--
-- A gpg keyid is the obvious example. But, if a gpg key is not
-- stored on the key servers, keysafe will instead use "".
data KeyId = KeyId B.ByteString
	deriving (Show)

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