aboutsummaryrefslogtreecommitdiff
path: root/Utility
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-12-18 16:50:58 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-12-18 16:51:41 -0400
commit09e3fc83f8e9a006cea239fabcff81692e938ddc (patch)
treec53b9058560e1c77c5888020233f294a5103e3b1 /Utility
parent32e2008eef8ed2cfbfc6e70db9b18bcff1d5fdf1 (diff)
p2p --pair with magic wormhole (untested)
It builds. I have not tried to run it yet. :) This commit was sponsored by Jake Vosloo on Patreon.
Diffstat (limited to 'Utility')
-rw-r--r--Utility/MagicWormhole.hs13
1 files changed, 12 insertions, 1 deletions
diff --git a/Utility/MagicWormhole.hs b/Utility/MagicWormhole.hs
index a71cc69e0..9ab804800 100644
--- a/Utility/MagicWormhole.hs
+++ b/Utility/MagicWormhole.hs
@@ -5,9 +5,11 @@
- License: BSD-2-clause
-}
-module Utility.MagicWormHole (
+module Utility.MagicWormhole (
Code,
mkCode,
+ toCode,
+ fromCode,
validCode,
CodeObserver,
CodeProducer,
@@ -32,9 +34,11 @@ import System.Exit
import Control.Concurrent
import Control.Exception
import Data.Char
+import Data.List
-- | A Magic Wormhole code.
newtype Code = Code String
+ deriving (Eq, Show)
-- | Smart constructor for Code
mkCode :: String -> Maybe Code
@@ -42,6 +46,13 @@ mkCode s
| validCode s = Just (Code s)
| otherwise = Nothing
+-- | Tries to fix up some common mistakes in a homan-entered code.
+toCode :: String -> Maybe Code
+toCode s = mkCode $ intercalate "-" $ words s
+
+fromCode :: Code -> String
+fromCode (Code s) = s
+
-- | Codes have the form number-word-word and may contain 2 or more words.
validCode :: String -> Bool
validCode s =