asn1-types 0.3.0 → 0.3.1
raw patch · 2 files changed
+81/−1 lines, 2 filesdep +memoryPVP ok
version bump matches the API change (PVP)
Dependencies added: memory
API changes (from Hackage documentation)
+ Data.ASN1.Pretty: Multiline :: Int -> PrettyType
+ Data.ASN1.Pretty: SingleLine :: PrettyType
+ Data.ASN1.Pretty: data PrettyType
+ Data.ASN1.Pretty: instance Eq PrettyType
+ Data.ASN1.Pretty: instance Show PrettyType
+ Data.ASN1.Pretty: pretty :: PrettyType -> [ASN1] -> String
Files
- Data/ASN1/Pretty.hs +78/−0
- asn1-types.cabal +3/−1
+ Data/ASN1/Pretty.hs view
@@ -0,0 +1,78 @@+-- |+-- Module : Data.ASN1.Pretty+-- License : BSD-style+-- Maintainer : Vincent Hanquez <vincent@snarc.org>+-- Stability : experimental+-- Portability : unknown+--+module Data.ASN1.Pretty+ ( pretty+ , PrettyType(..)+ ) where++import Data.ASN1.Types+import Data.ASN1.BitArray+import Data.ByteArray.Encoding (convertToBase, Base(..))+import Data.ByteString (ByteString)+import Numeric (showHex)++data PrettyType = Multiline Int -- Offset where to start+ | SingleLine+ deriving (Show,Eq)++-- | Pretty Print a list of ASN.1 element+pretty :: PrettyType -- ^ indent level in space character+ -> [ASN1] -- ^ stream of ASN1+ -> String+pretty (Multiline at) = prettyPrint at+ where+ indent n = replicate n ' '++ prettyPrint _ [] = ""+ prettyPrint n (x@(Start _) : xs) = indent n ++ p id x ++ prettyPrint (n+1) xs+ prettyPrint n (x@(End _) : xs) = indent (n-1) ++ p id x ++ prettyPrint (n-1) xs+ prettyPrint n (x : xs) = indent n ++ p id x ++ prettyPrint n xs++pretty SingleLine = prettyPrint+ where+ prettyPrint [] = ""+ prettyPrint (x@(Start _) : xs) = p id x ++ "," ++ prettyPrint xs+ prettyPrint (x@(End _) : xs) = p id x ++ "," ++ prettyPrint xs+ prettyPrint (x : xs) = p id x ++ "," ++ prettyPrint xs++p :: ([Char] -> t) -> ASN1 -> t+p put (Boolean b) = put ("bool: " ++ show b)+p put (IntVal i) = put ("int: " ++ showHex i "")+p put (BitString bits) = put ("bitstring: " ++ (hexdump $ bitArrayGetData bits))+p put (OctetString bs) = put ("octetstring: " ++ hexdump bs)+p put (Null) = put "null"+p put (OID is) = put ("OID: " ++ show is)+p put (Real d) = put ("real: " ++ show d)+p put (Enumerated _) = put "enum"+p put (Start Sequence) = put "{"+p put (End Sequence) = put "}"+p put (Start Set) = put "["+p put (End Set) = put "]"+p put (Start (Container x y)) = put ("< " ++ show x ++ " " ++ show y)+p put (End (Container x y)) = put ("> " ++ show x ++ " " ++ show y)+p put (ASN1String cs) = putCS put cs+p put (ASN1Time TimeUTC time tz) = put ("utctime: " ++ show time ++ " " ++ show tz)+p put (ASN1Time TimeGeneralized time tz) = put ("generalizedtime: " ++ show time ++ " " ++ show tz)+p put (Other tc tn x) = put ("other(" ++ show tc ++ "," ++ show tn ++ "," ++ show x ++ ")")++putCS :: ([Char] -> t) -> ASN1CharacterString -> t+putCS put (ASN1CharacterString UTF8 t) = put ("utf8string:" ++ show t)+putCS put (ASN1CharacterString Numeric bs) = put ("numericstring:" ++ hexdump bs)+putCS put (ASN1CharacterString Printable t) = put ("printablestring: " ++ show t)+putCS put (ASN1CharacterString T61 bs) = put ("t61string:" ++ show bs)+putCS put (ASN1CharacterString VideoTex bs) = put ("videotexstring:" ++ hexdump bs)+putCS put (ASN1CharacterString IA5 bs) = put ("ia5string:" ++ show bs)+putCS put (ASN1CharacterString Graphic bs) = put ("graphicstring:" ++ hexdump bs)+putCS put (ASN1CharacterString Visible bs) = put ("visiblestring:" ++ hexdump bs)+putCS put (ASN1CharacterString General bs) = put ("generalstring:" ++ hexdump bs)+putCS put (ASN1CharacterString UTF32 t) = put ("universalstring:" ++ show t)+putCS put (ASN1CharacterString Character bs) = put ("characterstring:" ++ hexdump bs)+putCS put (ASN1CharacterString BMP t) = put ("bmpstring: " ++ show t)++hexdump :: ByteString -> String+hexdump bs = show (convertToBase Base16 bs :: ByteString)
asn1-types.cabal view
@@ -1,5 +1,5 @@ Name: asn1-types-Version: 0.3.0+Version: 0.3.1 Description: ASN.1 standard types License: BSD3 License-file: LICENSE@@ -16,10 +16,12 @@ Library Build-Depends: base >= 3 && < 5 , bytestring+ , memory , hourglass Exposed-modules: Data.ASN1.BitArray Data.ASN1.OID+ Data.ASN1.Pretty Data.ASN1.Types Data.ASN1.Types.String Data.ASN1.Types.Lowlevel