forked from schmittlauch/Hash2Pub
more complex prototype example of modular parsing
This commit is contained in:
parent
7e6c4985ce
commit
7a20ea5225
|
@ -8,6 +8,7 @@ import qualified Data.ASN1.Types as ASN1 -- asn1-types package
|
|||
import qualified Data.ASN1.Parse as ASN1P
|
||||
import qualified Data.ByteString as BS
|
||||
import Data.Maybe (fromMaybe)
|
||||
import Debug.Trace (trace)
|
||||
|
||||
-- import Hash2Pub.Fedichord
|
||||
|
||||
|
@ -30,7 +31,17 @@ getUnicodeField ((ASN1.Start ASN1.Sequence) : _ : (ASN1.ASN1String strASN1) : _)
|
|||
|
||||
testParser :: ASN1P.ParseASN1 String
|
||||
testParser = do
|
||||
show <$> ASN1P.getNext
|
||||
foo <- ASN1P.onNextContainer ASN1.Sequence getAll
|
||||
return $ show foo
|
||||
|
||||
getAll :: ASN1P.ParseASN1 [ASN1.ASN1]
|
||||
getAll = ASN1P.getMany ASN1P.getNext
|
||||
|
||||
-- | run a function of the next elements of a container of specified type
|
||||
onNextContainer' :: ASN1.ASN1ConstructionType -> ASN1P.ParseASN1 a -> ASN1P.ParseASN1 a
|
||||
onNextContainer' ty f = do
|
||||
cont <- ASN1P.getNextContainer ty
|
||||
either ASN1P.throwParseError return . trace (show cont) $ ASN1P.runParseASN1 f cont
|
||||
|
||||
--stringParser asn1obj =
|
||||
-- fmap (fromMaybe "" $ ASN1.asn1CharacterToString) ASN1P.getNext
|
||||
|
|
Loading…
Reference in a new issue