summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2014-04-21 20:36:12 -0400
committerjoe <joe@jerkface.net>2014-04-21 20:36:12 -0400
commitb0e298c9203bb0b901dddc398ce00c96ff12071d (patch)
tree0b442d3b5ddfddee825999bd79c12bb58fcda363
parente8df0c028a87f1271d5a2ee258ac31d1913e5f3c (diff)
removed experimental code
-rw-r--r--ExperimentalCruft.hs199
-rw-r--r--KeyRing.hs202
2 files changed, 204 insertions, 197 deletions
diff --git a/ExperimentalCruft.hs b/ExperimentalCruft.hs
new file mode 100644
index 0000000..0c60731
--- /dev/null
+++ b/ExperimentalCruft.hs
@@ -0,0 +1,199 @@
1{-# LANGUAGE ExistentialQuantification #-}
2module ExperimentalCruft where
3
4import KeyRing
5
6data KeyRingAction a = KeyRingAction a | RunTimeAction (KeyRingRuntime -> a)
7
8data Kiki a =
9 SinglePass { passInfo :: KeyRingOperation
10 , rtAction :: KeyRingAction a }
11 | forall b.
12 MultiPass { passInfo :: KeyRingOperation
13 , passAction :: KeyRingAction b
14 , nextPass :: Kiki (b -> a)
15 }
16
17
18
19evalAction :: KeyRingRuntime -> KeyRingAction a -> a
20evalAction rt (KeyRingAction v) = v
21evalAction rt (RunTimeAction g) = g rt
22
23instance Monad KeyRingAction where
24 return x = KeyRingAction x
25 m >>= g = case m of
26 KeyRingAction v -> g v
27 RunTimeAction f -> RunTimeAction $ \rt -> evalAction rt (g $ f rt)
28
29instance Functor KeyRingAction where
30 fmap g (KeyRingAction v) = KeyRingAction $ g v
31 fmap g (RunTimeAction f) = RunTimeAction $ \rt -> g (f rt)
32
33{-
34argOut :: (KeyRingAction (a -> b)) -> a -> KeyRingAction b
35argOut = todo
36argIn :: (a -> KeyRingAction b) -> KeyRingAction (a->b)
37-}
38
39{-
40fmapWithRT :: (a -> KeyRingAction b) -> Kiki a -> Kiki b
41fmapWithRT g k@(SinglePass {}) = k { rtAction = action }
42 where
43 action = rtAction k >>= g
44fmapWithRT g (MultiPass p atn next) = MultiPass p atn next'
45 where
46 next' = fmapWithRT g' next {- next :: Kiki (x -> a) -}
47 -- g' :: ( (x->a) -> KeyRingAction b)
48 g' h = RunTimeAction $
49 \rt x -> case g (h x) of
50 KeyRingAction v -> v
51 RunTimeAction f -> f rt
52-}
53
54fmapWithRT :: KeyRingAction (a -> b) -> Kiki a -> Kiki b
55fmapWithRT g (SinglePass pass atn) = SinglePass pass atn'
56 where
57 atn' = g >>= flip fmap atn
58fmapWithRT g (MultiPass p atn next) = MultiPass p atn next'
59 where
60 next' = fmapWithRT g' next
61 g' = fmap (\gf h -> gf . h) g
62
63instance Functor Kiki where
64 fmap f k = fmapWithRT (return f) k
65
66{-
67instance Monad Kiki where
68 return x = SinglePass todo (return x)
69 k >>= f = kjoin $ fmap f k
70
71kikiAction :: Kiki a -> KeyRingAction a
72kikiAction (SinglePass _ atn) = atn
73kikiAction (MultiPass _ atn next) = do
74 x <- atn
75 g <- kikiAction next
76 return $ g x
77
78kjoin :: Kiki (Kiki a) -> Kiki a
79kjoin k = fmapWithRT eval' k
80 where
81 eval' :: KeyRingAction (Kiki a -> a)
82 eval' = RunTimeAction (\rt -> evalAction rt . kikiAction )
83
84 {-
85 kjoin :: Kiki (Kiki a) -> Kiki a
86 kjoin k = kjoin' (fmap kikiAction k)
87 where
88 ev rt (KeyRingAction v) = v
89 ev rt (RunTimeAction g) = g rt
90
91 kjoin' :: Kiki (KeyRingAction a) -> Kiki a
92 kjoin' (SinglePass pass atn) = SinglePass pass $ join atn
93 kjoin' (MultiPass pass atn next) = MultiPass pass atn next'
94 where
95 next' = todo
96 -}
97
98
99{-
100instance Functor Kiki where
101 fmap f (SinglePass pass atn)
102 = SinglePass pass (fmap f atn)
103 fmap f (MultiPass pass atn next)
104 = MultiPass pass atn (next >>= g)
105 where
106 g = todo
107-}
108
109{-
110data Kiki a = SinglePass (KeyRingOperation a)
111 | forall b. MultiPass (KeyRingOperation b) (Kiki (b -> a))
112
113instance Functor Kiki where
114 fmap f (SinglePass d) = SinglePass $ case kAction d of
115 KeyRingAction v -> d { kAction = KeyRingAction (f v) }
116 RunTimeAction g -> d { kAction = RunTimeAction (f . g) }
117 fmap f (MultiPass p k)= MultiPass p (fmap (f .) k)
118
119eval :: KeyRingRuntime -> Kiki a -> a
120eval rt (SinglePass (KeyRingOperation { kAction = KeyRingAction v})) = v
121eval rt (SinglePass (KeyRingOperation { kAction = RunTimeAction f})) = f rt
122eval rt (MultiPass p kk) = eval rt kk $ eval rt (SinglePass p)
123
124fmapWithRT :: (KeyRingRuntime -> a -> b) -> Kiki a -> Kiki b
125fmapWithRT g (SinglePass d@(KeyRingOperation { kAction = KeyRingAction v}))
126 = SinglePass $ d { kAction = RunTimeAction (\rt -> g rt v) }
127fmapWithRT g (SinglePass d@(KeyRingOperation { kAction = RunTimeAction f}))
128 = SinglePass $ d { kAction = RunTimeAction f' }
129 where f' rt = g rt (f rt)
130fmapWithRT g (MultiPass p kk) = MultiPass p (fmapWithRT g' kk)
131 where g' rt h = g rt . h
132
133kjoin :: Kiki (Kiki a) -> Kiki a
134kjoin k = fmapWithRT eval k
135
136passCount :: Kiki a -> Int
137passCount (MultiPass _ k) = 1 + passCount k
138passCount (SinglePass {}) = 1
139
140instance Monad Kiki where
141 return x = SinglePass (kret x)
142 k >>= f = kjoin (fmap f k)
143-}
144
145
146-- Kiki a -> a -> Kiki b
147
148atRuntime :: (KeyRingRuntime -> IO (a,KeyRingRuntime)) -> Kiki a
149atRuntime = todo
150
151goHome :: Maybe FilePath -> Kiki ()
152goHome p = todo -- SinglePass $ (kret ()) { homeSpec = p }
153
154syncRing :: InputFile -> Kiki ()
155syncRing = todo
156
157syncSubKey :: String -> FilePath -> String -> Kiki ()
158syncSubKey usage path cmd = todo
159
160syncWallet :: FilePath -> Kiki ()
161syncWallet = todo
162
163usePassphraseFD :: Int -> Kiki ()
164usePassphraseFD = todo
165
166{-
167importAll :: Kiki ()
168importAll = todo
169-}
170
171importAllAuthentic :: Kiki ()
172importAllAuthentic = todo
173
174signSelfAuthorized :: Kiki ()
175signSelfAuthorized = todo
176
177showIdentity :: Message -> String
178showIdentity = todo
179
180identities :: Kiki [Message]
181identities = todo
182
183currentIdentity :: Kiki Message
184currentIdentity = todo
185
186identityBySpec :: String -> Kiki Message
187identityBySpec = todo
188
189identityBySSHKey :: String -> Kiki Message
190identityBySSHKey = todo
191
192keyBySpec :: String -> Kiki Packet
193keyBySpec = todo
194
195walletInputFormat :: Packet -> String
196walletInputFormat = todo
197
198-}
199
diff --git a/KeyRing.hs b/KeyRing.hs
index 16e7751..c3a80d9 100644
--- a/KeyRing.hs
+++ b/KeyRing.hs
@@ -1,7 +1,6 @@
1{-# LANGUAGE CPP #-} 1{-# LANGUAGE CPP #-}
2{-# LANGUAGE TupleSections #-} 2{-# LANGUAGE TupleSections #-}
3{-# LANGUAGE ViewPatterns #-} 3{-# LANGUAGE ViewPatterns #-}
4{-# LANGUAGE ExistentialQuantification #-}
5{-# LANGUAGE OverloadedStrings #-} 4{-# LANGUAGE OverloadedStrings #-}
6{-# LANGUAGE DeriveFunctor #-} 5{-# LANGUAGE DeriveFunctor #-}
7{-# LANGUAGE DoAndIfThenElse #-} 6{-# LANGUAGE DoAndIfThenElse #-}
@@ -16,6 +15,7 @@ module KeyRing
16 , guardAuthentic 15 , guardAuthentic
17 , Hosts.Hosts 16 , Hosts.Hosts
18 , importPublic 17 , importPublic
18 , importSecret
19 , PacketUpdate(..) 19 , PacketUpdate(..)
20 , isCryptoCoinKey 20 , isCryptoCoinKey
21 , isKey 21 , isKey
@@ -36,7 +36,6 @@ module KeyRing
36 , pkcs8 36 , pkcs8
37 , RSAPublicKey(..) 37 , RSAPublicKey(..)
38 , rsaKeyFromPacket 38 , rsaKeyFromPacket
39 , RSAPublicKey
40 , KeyRingRuntime(..) 39 , KeyRingRuntime(..)
41 , runKeyRing 40 , runKeyRing
42 , secretToPublic 41 , secretToPublic
@@ -112,7 +111,7 @@ import DotLock
112import ProcessUtils (systemEnv, ExitCode(ExitFailure, ExitSuccess) ) 111import ProcessUtils (systemEnv, ExitCode(ExitFailure, ExitSuccess) )
113 112
114-- DER-encoded elliptic curve ids 113-- DER-encoded elliptic curve ids
115nistp256_id = 0x2a8648ce3d030107 114-- nistp256_id = 0x2a8648ce3d030107
116secp256k1_id = 0x2b8104000a 115secp256k1_id = 0x2b8104000a
117-- "\x2a\x86\x48\xce\x3d\x03\x01\x07" 116-- "\x2a\x86\x48\xce\x3d\x03\x01\x07"
118{- OID Curve description Curve name 117{- OID Curve description Curve name
@@ -199,8 +198,6 @@ data KeyRingRuntime = KeyRingRuntime
199 , rtKeyDB :: KeyDB 198 , rtKeyDB :: KeyDB
200 } 199 }
201 200
202data KeyRingAction a = KeyRingAction a | RunTimeAction (KeyRingRuntime -> a)
203
204-- | TODO: Packet Update should have deletiong action 201-- | TODO: Packet Update should have deletiong action
205-- and any other kind of roster entry level 202-- and any other kind of roster entry level
206-- action. 203-- action.
@@ -391,7 +388,7 @@ data KikiResult a = KikiResult
391 388
392keyPacket (KeyData k _ _ _) = packet k 389keyPacket (KeyData k _ _ _) = packet k
393 390
394subkeyPacket (SubKey k _ ) = packet k 391-- subkeyPacket (SubKey k _ ) = packet k
395subkeyMappedPacket (SubKey k _ ) = k 392subkeyMappedPacket (SubKey k _ ) = k
396 393
397 394
@@ -675,6 +672,7 @@ selectKey0 wantPublic (spec,mtag) db = do
675 zs = snd $ seek_key subspec ys1 672 zs = snd $ seek_key subspec ys1
676 listToMaybe zs 673 listToMaybe zs
677 674
675{-
678selectAll :: Bool -> (KeySpec,Maybe String) -> KeyDB -> [(Packet,Maybe Packet)] 676selectAll :: Bool -> (KeySpec,Maybe String) -> KeyDB -> [(Packet,Maybe Packet)]
679selectAll wantPublic (spec,mtag) db = do 677selectAll wantPublic (spec,mtag) db = do
680 let Message ps = flattenKeys wantPublic db 678 let Message ps = flattenKeys wantPublic db
@@ -688,6 +686,7 @@ selectAll wantPublic (spec,mtag) db = do
688 z <- take 1 zs 686 z <- take 1 zs
689 (y,Just z):search (drop 1 zs) 687 (y,Just z):search (drop 1 zs)
690 in search (drop 1 ys) 688 in search (drop 1 ys)
689-}
691 690
692seek_key :: KeySpec -> [Packet] -> ([Packet],[Packet]) 691seek_key :: KeySpec -> [Packet] -> ([Packet],[Packet])
693seek_key (KeyGrip grip) sec = (pre, subs) 692seek_key (KeyGrip grip) sec = (pre, subs)
@@ -2381,194 +2380,3 @@ fmapWithRT g (MultiPass p kk) = MultiPass p (fmapWithRT g' kk)
2381-} 2380-}
2382 2381
2383 2382
2384data Kiki a =
2385 SinglePass { passInfo :: KeyRingOperation
2386 , rtAction :: KeyRingAction a }
2387 | forall b.
2388 MultiPass { passInfo :: KeyRingOperation
2389 , passAction :: KeyRingAction b
2390 , nextPass :: Kiki (b -> a)
2391 }
2392
2393
2394
2395evalAction :: KeyRingRuntime -> KeyRingAction a -> a
2396evalAction rt (KeyRingAction v) = v
2397evalAction rt (RunTimeAction g) = g rt
2398
2399instance Monad KeyRingAction where
2400 return x = KeyRingAction x
2401 m >>= g = case m of
2402 KeyRingAction v -> g v
2403 RunTimeAction f -> RunTimeAction $ \rt -> evalAction rt (g $ f rt)
2404
2405instance Functor KeyRingAction where
2406 fmap g (KeyRingAction v) = KeyRingAction $ g v
2407 fmap g (RunTimeAction f) = RunTimeAction $ \rt -> g (f rt)
2408
2409{-
2410argOut :: (KeyRingAction (a -> b)) -> a -> KeyRingAction b
2411argOut = todo
2412argIn :: (a -> KeyRingAction b) -> KeyRingAction (a->b)
2413-}
2414
2415{-
2416fmapWithRT :: (a -> KeyRingAction b) -> Kiki a -> Kiki b
2417fmapWithRT g k@(SinglePass {}) = k { rtAction = action }
2418 where
2419 action = rtAction k >>= g
2420fmapWithRT g (MultiPass p atn next) = MultiPass p atn next'
2421 where
2422 next' = fmapWithRT g' next {- next :: Kiki (x -> a) -}
2423 -- g' :: ( (x->a) -> KeyRingAction b)
2424 g' h = RunTimeAction $
2425 \rt x -> case g (h x) of
2426 KeyRingAction v -> v
2427 RunTimeAction f -> f rt
2428-}
2429
2430fmapWithRT :: KeyRingAction (a -> b) -> Kiki a -> Kiki b
2431fmapWithRT g (SinglePass pass atn) = SinglePass pass atn'
2432 where
2433 atn' = g >>= flip fmap atn
2434fmapWithRT g (MultiPass p atn next) = MultiPass p atn next'
2435 where
2436 next' = fmapWithRT g' next
2437 g' = fmap (\gf h -> gf . h) g
2438
2439instance Functor Kiki where
2440 fmap f k = fmapWithRT (return f) k
2441
2442{-
2443instance Monad Kiki where
2444 return x = SinglePass todo (return x)
2445 k >>= f = kjoin $ fmap f k
2446
2447kikiAction :: Kiki a -> KeyRingAction a
2448kikiAction (SinglePass _ atn) = atn
2449kikiAction (MultiPass _ atn next) = do
2450 x <- atn
2451 g <- kikiAction next
2452 return $ g x
2453
2454kjoin :: Kiki (Kiki a) -> Kiki a
2455kjoin k = fmapWithRT eval' k
2456 where
2457 eval' :: KeyRingAction (Kiki a -> a)
2458 eval' = RunTimeAction (\rt -> evalAction rt . kikiAction )
2459
2460 {-
2461 kjoin :: Kiki (Kiki a) -> Kiki a
2462 kjoin k = kjoin' (fmap kikiAction k)
2463 where
2464 ev rt (KeyRingAction v) = v
2465 ev rt (RunTimeAction g) = g rt
2466
2467 kjoin' :: Kiki (KeyRingAction a) -> Kiki a
2468 kjoin' (SinglePass pass atn) = SinglePass pass $ join atn
2469 kjoin' (MultiPass pass atn next) = MultiPass pass atn next'
2470 where
2471 next' = todo
2472 -}
2473
2474
2475{-
2476instance Functor Kiki where
2477 fmap f (SinglePass pass atn)
2478 = SinglePass pass (fmap f atn)
2479 fmap f (MultiPass pass atn next)
2480 = MultiPass pass atn (next >>= g)
2481 where
2482 g = todo
2483-}
2484
2485{-
2486data Kiki a = SinglePass (KeyRingOperation a)
2487 | forall b. MultiPass (KeyRingOperation b) (Kiki (b -> a))
2488
2489instance Functor Kiki where
2490 fmap f (SinglePass d) = SinglePass $ case kAction d of
2491 KeyRingAction v -> d { kAction = KeyRingAction (f v) }
2492 RunTimeAction g -> d { kAction = RunTimeAction (f . g) }
2493 fmap f (MultiPass p k)= MultiPass p (fmap (f .) k)
2494
2495eval :: KeyRingRuntime -> Kiki a -> a
2496eval rt (SinglePass (KeyRingOperation { kAction = KeyRingAction v})) = v
2497eval rt (SinglePass (KeyRingOperation { kAction = RunTimeAction f})) = f rt
2498eval rt (MultiPass p kk) = eval rt kk $ eval rt (SinglePass p)
2499
2500fmapWithRT :: (KeyRingRuntime -> a -> b) -> Kiki a -> Kiki b
2501fmapWithRT g (SinglePass d@(KeyRingOperation { kAction = KeyRingAction v}))
2502 = SinglePass $ d { kAction = RunTimeAction (\rt -> g rt v) }
2503fmapWithRT g (SinglePass d@(KeyRingOperation { kAction = RunTimeAction f}))
2504 = SinglePass $ d { kAction = RunTimeAction f' }
2505 where f' rt = g rt (f rt)
2506fmapWithRT g (MultiPass p kk) = MultiPass p (fmapWithRT g' kk)
2507 where g' rt h = g rt . h
2508
2509kjoin :: Kiki (Kiki a) -> Kiki a
2510kjoin k = fmapWithRT eval k
2511
2512passCount :: Kiki a -> Int
2513passCount (MultiPass _ k) = 1 + passCount k
2514passCount (SinglePass {}) = 1
2515
2516instance Monad Kiki where
2517 return x = SinglePass (kret x)
2518 k >>= f = kjoin (fmap f k)
2519-}
2520
2521
2522-- Kiki a -> a -> Kiki b
2523
2524atRuntime :: (KeyRingRuntime -> IO (a,KeyRingRuntime)) -> Kiki a
2525atRuntime = todo
2526
2527goHome :: Maybe FilePath -> Kiki ()
2528goHome p = todo -- SinglePass $ (kret ()) { homeSpec = p }
2529
2530syncRing :: InputFile -> Kiki ()
2531syncRing = todo
2532
2533syncSubKey :: String -> FilePath -> String -> Kiki ()
2534syncSubKey usage path cmd = todo
2535
2536syncWallet :: FilePath -> Kiki ()
2537syncWallet = todo
2538
2539usePassphraseFD :: Int -> Kiki ()
2540usePassphraseFD = todo
2541
2542{-
2543importAll :: Kiki ()
2544importAll = todo
2545-}
2546
2547importAllAuthentic :: Kiki ()
2548importAllAuthentic = todo
2549
2550signSelfAuthorized :: Kiki ()
2551signSelfAuthorized = todo
2552
2553showIdentity :: Message -> String
2554showIdentity = todo
2555
2556identities :: Kiki [Message]
2557identities = todo
2558
2559currentIdentity :: Kiki Message
2560currentIdentity = todo
2561
2562identityBySpec :: String -> Kiki Message
2563identityBySpec = todo
2564
2565identityBySSHKey :: String -> Kiki Message
2566identityBySSHKey = todo
2567
2568keyBySpec :: String -> Kiki Packet
2569keyBySpec = todo
2570
2571walletInputFormat :: Packet -> String
2572walletInputFormat = todo
2573
2574-}