packages feed

language-asn 0.1.0.0 → 0.1.1.0

raw patch · 3 files changed

+61/−20 lines, 3 filesdep +aesondep ~basedep ~hashabledep ~primitivenew-uploaderPVP ok

version bump matches the API change (PVP)

Dependencies added: aeson

Dependency ranges changed: base, hashable, primitive

API changes (from Hackage documentation)

+ Language.Asn.Types.Internal: instance Data.Aeson.Types.FromJSON.FromJSON Language.Asn.Types.Internal.ObjectIdentifier
+ Language.Asn.Types.Internal: instance Data.Aeson.Types.FromJSON.FromJSONKey Language.Asn.Types.Internal.ObjectIdentifier
+ Language.Asn.Types.Internal: instance Data.Aeson.Types.ToJSON.ToJSON Language.Asn.Types.Internal.ObjectIdentifier
+ Language.Asn.Types.Internal: oidJsonParser :: Text -> Parser ObjectIdentifier
+ Language.Asn.Types.Internal: parseWord :: Text -> Maybe Word

Files

CHANGELOG.md view
@@ -3,10 +3,17 @@ `language-asn` uses [PVP Versioning][1]. The changelog is available [on GitHub][2]. -0.0.0-=====+0.1.1.0+======= -* Initially created.+* Added `FromJSON`, `FromJSONKey`, and `ToJSON` instances to+  `ObjectIdentifier`.++0.1.0.0+=======++* Moved all ASN.1 code from the now-deprecated `asn1-codec` into+  this library.  [1]: https://pvp.haskell.org [2]: https://github.com/chessai/language-asn/releases
language-asn.cabal view
@@ -2,11 +2,11 @@ name:   language-asn version:-  0.1.0.0+  0.1.1.0 synopsis:   ASN.1 encoding and decoding description:-  ASN.1 language implementation. ASN.1 is used tightly with SNMP.+  ASN.1 language implementation. SNMP uses ASN.1 for serialization. homepage:   https://github.com/chessai/language-asn.git license:@@ -32,20 +32,21 @@  library   exposed-modules:-    Language.Asn.Encoding     Language.Asn.Decoding+    Language.Asn.Encoding     Language.Asn.ObjectIdentifier     Language.Asn.Types     Language.Asn.Types.Internal   build-depends:-      base >=4.9 && <4.13+    , aeson >= 1.2 && < 1.5+    , base >=4.9 && <4.13     , bytestring >= 0.10 && < 0.11     , contravariant >= 1.3 && < 1.6-    , vector >= 0.11 && < 0.13-    , primitive >= 0.6.4 && < 7+    , hashable >= 1.2 && < 1.3     , pretty >= 1.1 && < 1.2+    , primitive >= 0.6.4 && < 7     , text >= 1.2 && < 1.3-    , hashable >= 1.2 && < 1.3+    , vector >= 0.11 && < 0.13   hs-source-dirs:     src   default-language:
src/Language/Asn/Types/Internal.hs view
@@ -14,22 +14,31 @@ module Language.Asn.Types.Internal where  import Prelude hiding (sequence,null)-import Data.String (IsString)++import Data.Aeson (ToJSON,FromJSON,FromJSONKey) import Data.ByteString (ByteString)-import Data.Text (Text)-#if !MIN_VERSION_base(4,11,0)-import Data.Monoid (Monoid)-#endif-import Data.Semigroup (Semigroup)-import Data.Word-import Data.Primitive (PrimArray)-import GHC.Int (Int(..))+import Data.Functor.Contravariant (Contravariant(..)) import Data.Hashable (Hashable(..))+import Data.Primitive (PrimArray)+import Data.Semigroup (Semigroup)+import Data.String (IsString)+import Data.Text (Text)+import Data.Word (Word64,Word8) import GHC.Generics (Generic)-import Data.Functor.Contravariant (Contravariant(..))+import GHC.Int (Int(..))++import qualified Data.Aeson as AE+import qualified Data.Aeson.Types as AE import qualified Data.ByteString.Lazy as LB+import qualified Data.List as L+import qualified Data.Text as T+import qualified Data.Text.Read as TR import qualified GHC.Exts as E +#if !MIN_VERSION_base(4,11,0)+import Data.Monoid (Monoid)+#endif+ data AsnEncoding a   = EncSequence [Field a]   | forall b. EncSequenceOf (a -> [b]) (AsnEncoding b)@@ -74,6 +83,30 @@ newtype ObjectIdentifier = ObjectIdentifier   { getObjectIdentifier :: PrimArray Word   } deriving (Eq,Ord,Show,Generic)++instance ToJSON ObjectIdentifier where+  toJSON (ObjectIdentifier xs) = AE.toJSON+    $ mconcat+    $ L.intersperse (T.singleton '.')+    $ map (T.pack . show)+    $ E.toList xs++instance FromJSONKey ObjectIdentifier where+  fromJSONKey = AE.FromJSONKeyTextParser oidJsonParser++instance FromJSON ObjectIdentifier where+  parseJSON = AE.withText "ObjectIdentifier" oidJsonParser++oidJsonParser :: Text -> AE.Parser ObjectIdentifier+oidJsonParser t =+  case fmap (ObjectIdentifier . E.fromList) (mapM parseWord (T.splitOn (T.singleton '.') t)) of+    Nothing -> fail ("could not recognize " ++ T.unpack t ++ " as an OID")+    Just x -> return x++parseWord :: Text -> Maybe Word+parseWord t = case TR.decimal t of+  Right (i,leftovers) -> if T.null leftovers then Just i else Nothing+  Left _ -> Nothing  instance Hashable ObjectIdentifier where   hash (ObjectIdentifier v) = hash (E.toList v)