File: PrivateKeys.hs

package info (click to toggle)
haskell-hackage-security 0.6.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 520 kB
  • sloc: haskell: 5,987; makefile: 9
file content (69 lines) | stat: -rw-r--r-- 2,191 bytes parent folder | download | duplicates (5)
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
62
63
64
65
66
67
68
69
module TestSuite.PrivateKeys (
    PrivateKeys(..)
  , createPrivateKeys
  , privateKeysEnv
  , privateKeysRoles
  ) where

-- stdlib
import Control.Monad

-- hackage-security
import Hackage.Security.Client
import Hackage.Security.Key.Env (KeyEnv)
import Hackage.Security.Util.Some
import qualified Hackage.Security.Key.Env as KeyEnv

{-------------------------------------------------------------------------------
  All private keys
-------------------------------------------------------------------------------}

data PrivateKeys = PrivateKeys {
      privateRoot      :: [Some Key]
    , privateTarget    :: [Some Key]
    , privateSnapshot  :: Some Key
    , privateTimestamp :: Some Key
    , privateMirrors   :: Some Key
    }

createPrivateKeys :: IO PrivateKeys
createPrivateKeys = do
    privateRoot      <- replicateM 3 $ createKey' KeyTypeEd25519
    privateTarget    <- replicateM 3 $ createKey' KeyTypeEd25519
    privateSnapshot  <- createKey' KeyTypeEd25519
    privateTimestamp <- createKey' KeyTypeEd25519
    privateMirrors   <- createKey' KeyTypeEd25519
    return PrivateKeys{..}

privateKeysEnv :: PrivateKeys -> KeyEnv
privateKeysEnv PrivateKeys{..} = KeyEnv.fromKeys $ concat [
      privateRoot
    , privateTarget
    , [privateSnapshot]
    , [privateTimestamp]
    , [privateMirrors]
    ]

privateKeysRoles :: PrivateKeys -> RootRoles
privateKeysRoles PrivateKeys{..} = RootRoles {
      rootRolesRoot      = RoleSpec {
          roleSpecKeys      = map somePublicKey privateRoot
        , roleSpecThreshold = KeyThreshold 2
        }
    , rootRolesSnapshot  = RoleSpec {
          roleSpecKeys      = [somePublicKey privateSnapshot]
        , roleSpecThreshold = KeyThreshold 1
        }
    , rootRolesTargets   = RoleSpec {
          roleSpecKeys      = map somePublicKey privateTarget
        , roleSpecThreshold = KeyThreshold 2
        }
    , rootRolesTimestamp = RoleSpec {
          roleSpecKeys      = [somePublicKey privateTimestamp]
        , roleSpecThreshold = KeyThreshold 1
        }
    , rootRolesMirrors   = RoleSpec {
          roleSpecKeys      = [somePublicKey privateMirrors]
        , roleSpecThreshold = KeyThreshold 1
        }
    }