{-
m0Val :: M0Rep
m0Val = cons (bit 0) empty

m1Val :: M1Rep
m1Val = cons (bit 1) empty
-}


readPubEK :: IO TPM_PUBKEY
readPubEK = do
  handle <- openFile exportEKFileName ReadMode
  pubKeyString <- hGetLine handle
  let pubKey :: TPM_PUBKEY
      pubKey = read pubKeyString
  hClose handle
  return pubKey
  
  
{-
testRequest :: IO Request
testRequest = do 
  (pcrSelect, nonce) <- mkTPMRequest ([0..23]::[Word8])
  let mReq = mkMeasureReq [0..2]
  return (Request mReq pcrSelect nonce)

testResponse :: IO Response
testResponse = do 
  pubKey <- readPubEK
  comp <- readComp
  putStrLn $ show comp
  let caCert = Signed pubKey m1Val
      quote = Quote comp (fromStrict (Char8.pack "hello")) --m0Val
  
  return $ Response evPack caCert quote

 where evPack = EvidencePackage [M0 m0Val, M1 m1Val] (TPM_NONCE m1Val)                                                     m1Val

-}  
  
  
  
{-  
goldenFileName :: String 
goldenFileName= "goldenPcrComosite.txt"

exportEKFileName = "attEKPubKey.txt"
-}


{-
readComp :: IO TPM_PCR_COMPOSITE
readComp = do
  handle <- openFile goldenFileName ReadMode
  compString <- hGetLine handle
  let comp :: TPM_PCR_COMPOSITE
      comp = read compString
  hClose handle
  return comp
-}


{-
sendPubKeyRequest :: Bool -> IO LibXenVChan
sendPubKeyRequest  b = do
  putStrLn $ "Appraiser Domain id: "++ show appId
  chan <- client_init attId
  putStrLn $ "\n" ++ "Appraiser Sending: "++ 
                  "PubKey Request: " ++ (show b) ++ "\n"
  send chan $ b
  return chan
-}

{-
receivePubKeyResponse :: LibXenVChan -> IO PubKeyResponse
receivePubKeyResponse chan = do
  ctrlWait chan
  resp :: PubKeyResponse <- receive chan --TODO: error handling?
  putStrLn $ "\n" ++ "Appraiser Received: " ++ "Pubkey Response: " 
                  ++ show resp ++ "\n"
  return resp
-}
readPubEK :: IO TPM_PUBKEY
readPubEK = do
  handle <- openFile exportEKFileName ReadMode
  pubKeyString <- hGetLine handle
  let pubKey :: TPM_PUBKEY
      pubKey = read pubKeyString
  hClose handle
  return pubKey
  
  
{-
testRequest :: IO Request
testRequest = do 
  (pcrSelect, nonce) <- mkTPMRequest ([0..23]::[Word8])
  let mReq = mkMeasureReq [0..2]
  return (Request mReq pcrSelect nonce)

testResponse :: IO Response
testResponse = do 
  pubKey <- readPubEK
  comp <- readComp
  putStrLn $ show comp
  let caCert = Signed pubKey m1Val
      quote = Quote comp (fromStrict (Char8.pack "hello")) --m0Val
  
  return $ Response evPack caCert quote

 where evPack = EvidencePackage [M0 m0Val, M1 m1Val] (TPM_NONCE m1Val)                                                     m1Val

-}  
  
  
  
{-  
goldenFileName :: String 
goldenFileName= "goldenPcrComosite.txt"

exportEKFileName = "attEKPubKey.txt"
-}


{-
readComp :: IO TPM_PCR_COMPOSITE
readComp = do
  handle <- openFile goldenFileName ReadMode
  compString <- hGetLine handle
  let comp :: TPM_PCR_COMPOSITE
      comp = read compString
  hClose handle
  return comp
-}


{-
sendPubKeyRequest :: Bool -> IO LibXenVChan
sendPubKeyRequest  b = do
  putStrLn $ "Appraiser Domain id: "++ show appId
  chan <- client_init attId
  putStrLn $ "\n" ++ "Appraiser Sending: "++ 
                  "PubKey Request: " ++ (show b) ++ "\n"
  send chan $ b
  return chan
-}

{-
receivePubKeyResponse :: LibXenVChan -> IO PubKeyResponse
receivePubKeyResponse chan = do
  ctrlWait chan
  resp :: PubKeyResponse <- receive chan --TODO: error handling?
  putStrLn $ "\n" ++ "Appraiser Received: " ++ "Pubkey Response: " 
                  ++ show resp ++ "\n"
  return resp
-}
readPubEK = do
  handle <- openFile exportEKFileName ReadMode
  pubKeyString <- hGetLine handle
  let pubKey :: TPM_PUBKEY
      pubKey = read pubKeyString
  hClose handle
  return pubKey
  
  
{-
testRequest :: IO Request
testRequest = do 
  (pcrSelect, nonce) <- mkTPMRequest ([0..23]::[Word8])
  let mReq = mkMeasureReq [0..2]
  return (Request mReq pcrSelect nonce)

testResponse :: IO Response
testResponse = do 
  pubKey <- readPubEK
  comp <- readComp
  putStrLn $ show comp
  let caCert = Signed pubKey m1Val
      quote = Quote comp (fromStrict (Char8.pack "hello")) --m0Val
  
  return $ Response evPack caCert quote

 where evPack = EvidencePackage [M0 m0Val, M1 m1Val] (TPM_NONCE m1Val)                                                     m1Val

-}  
  
  
  
{-  
goldenFileName :: String 
goldenFileName= "goldenPcrComosite.txt"

exportEKFileName = "attEKPubKey.txt"
-}


{-
readComp :: IO TPM_PCR_COMPOSITE
readComp = do
  handle <- openFile goldenFileName ReadMode
  compString <- hGetLine handle
  let comp :: TPM_PCR_COMPOSITE
      comp = read compString
  hClose handle
  return comp
-}


{-
sendPubKeyRequest :: Bool -> IO LibXenVChan
sendPubKeyRequest  b = do
  putStrLn $ "Appraiser Domain id: "++ show appId
  chan <- client_init attId
  putStrLn $ "\n" ++ "Appraiser Sending: "++ 
                  "PubKey Request: " ++ (show b) ++ "\n"
  send chan $ b
  return chan
-}

{-
receivePubKeyResponse :: LibXenVChan -> IO PubKeyResponse
receivePubKeyResponse chan = do
  ctrlWait chan
  resp :: PubKeyResponse <- receive chan --TODO: error handling?
  putStrLn $ "\n" ++ "Appraiser Received: " ++ "Pubkey Response: " 
                  ++ show resp ++ "\n"
  return resp
-}