packages feed

crypton-asn1-types 0.3.5 → 0.3.6

raw patch · 3 files changed

+126/−3 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.ASN1.Stream: getConstructedEnd :: Int -> [ASN1] -> ([ASN1], [ASN1])
+ Data.ASN1.Stream: getConstructedEndRepr :: [ASN1Repr] -> ([ASN1Repr], [ASN1Repr])
+ Data.ASN1.Stream: type ASN1Repr = (ASN1, [ASN1Event])

Files

CHANGELOG.md view
@@ -6,6 +6,12 @@ and this project adheres to the
 [Haskell Package Versioning Policy](https://pvp.haskell.org/).
 
+## 0.3.6
+
+* Expose `Data.ASN1.Stream`, spun out of the `crypton-asn1-encoding-0.9.6`
+  package.
+* Use the `other-extensions` field in the Cabal file.
+
 ## 0.3.5
 
 * Move library modules to directory `src`.
crypton-asn1-types.cabal view
@@ -1,11 +1,11 @@-cabal-version: 1.18
+cabal-version: 1.18  -- This file has been generated from package.yaml by hpack version 0.38.1. -- -- see: https://github.com/sol/hpack  name:           crypton-asn1-types-version:        0.3.5+version:        0.3.6 synopsis:       ASN.1 types description:    A library providing types representing the Abstract Syntax Notation One                 (ASN.1) standard.@@ -34,10 +34,13 @@       Data.ASN1.OID       Data.ASN1.Pretty       Data.ASN1.Types-      Data.ASN1.Types.String       Data.ASN1.Types.Lowlevel+      Data.ASN1.Types.String+      Data.ASN1.Stream   hs-source-dirs:       src+  other-extensions:+      CPP   ghc-options: -Wall   build-depends:       base >=3 && <5
+ src/Data/ASN1/Stream.hs view
@@ -0,0 +1,114 @@+{- |
+Module      : Data.ASN1.Stream
+License     : BSD-style
+Copyright   : (c) 2010-2013 Vincent Hanquez <vincent@snarc.org>
+Stability   : experimental
+Portability : unknown
+-}
+
+module Data.ASN1.Stream
+  ( ASN1Repr
+    -- * Utilities
+  , getConstructedEnd
+  , getConstructedEndRepr
+  ) where
+
+import           Data.ASN1.Types ( ASN1 (..) )
+import           Data.ASN1.Types.Lowlevel ( ASN1Event )
+
+-- | Type synonym representing pairs of a ASN.1 value and a list of ASN.1
+-- events.
+--
+-- This association is sometimes needed in order to know the exact byte sequence
+-- leading to an ASN.1 value. For example, in the case of a cryptographic
+-- signature.
+type ASN1Repr = (ASN1, [ASN1Event])
+
+-- | For the given list of ASN.1 values, assumed to follow a 'Start' value:
+--
+-- If the list is empty, return a pair of empty lists.
+--
+-- Otherwise, return a list of values up to (but excluding) the corresponding
+-- 'End' value (if any), and a list of the remaining ASN.1 values.
+getConstructedEnd ::
+     Int
+     -- ^ The number of additional 'Start' values encountered, @0@ initially.
+  -> [ASN1]
+  -> ([ASN1], [ASN1])
+-- The given list is empty.
+getConstructedEnd _ [] = ([], [])
+
+-- The first item is another 'Start'.
+getConstructedEnd i (x@(Start _) : xs) =
+  let (ys, zs) = getConstructedEnd (i + 1) xs
+  in  (x : ys, zs)
+
+-- The first item is the corresponding 'End'.
+getConstructedEnd 0 ((End _) : xs) = ([], xs)
+
+-- The first item is an 'End', but not the corresponding 'End'.
+getConstructedEnd i (x@(End _) : xs) =
+  let (ys, zs) = getConstructedEnd (i - 1) xs
+  in  (x : ys, zs)
+
+-- The first item is not an 'End' or another 'Start'.
+getConstructedEnd i (x : xs) =
+  let (ys, zs) = getConstructedEnd i xs
+  in  (x : ys, zs)
+
+-- | For the given list of 'ASN1Repr' pairs:
+--
+-- If the list is empty, return a pair of empty lists.
+--
+-- If the first item represents a 'Start' value, return a list of pairs up to
+-- the corresponding 'End' value (if any) (including the 'Start' and any 'End')
+-- and a list of the remaining 'ASN1Repr' pairs.
+--
+-- Otherwise, return a list of that first item and a list of the
+-- remaining pairs.
+getConstructedEndRepr :: [ASN1Repr] -> ([ASN1Repr], [ASN1Repr])
+-- The given list is empty.
+getConstructedEndRepr [] = ([], [])
+
+-- The first item represents a 'Start'.
+getConstructedEndRepr (x@(Start _, _) : xs) =
+  let (ys, zs) = getConstructedEndRepr' 1 xs
+  in  (x : ys, zs)
+
+-- The first item does not represent a 'Start'.
+getConstructedEndRepr (x : xs) = ([x], xs)
+
+-- | For the given list of 'ASN1Repr' pairs:
+--
+-- If the list is empty, return a pair of empty lists.
+--
+-- If there is no corresponding 'Start', return an empty list and the list of
+-- 'ASN1Repr' pairs.
+--
+-- Otherwise, return a list of values up to (and including) the corresponding
+-- 'End' value (if any), and a list of the remaining  'ASN1Repr' pairs.
+getConstructedEndRepr' ::
+     Int
+     -- ^ The number of 'Start' values encountered.
+  -> [ASN1Repr]
+  -> ([ASN1Repr], [ASN1Repr])
+-- The given list is empty.
+getConstructedEndRepr' _ [] = ([], [])
+
+-- There is no, or no longer a, corresponding 'Start'.
+getConstructedEndRepr' 0 xs = ([], xs)
+
+-- The first item is another 'Start'.
+getConstructedEndRepr' i (x@(Start _, _) : xs) =
+  let (ys, zs) = getConstructedEndRepr' (i + 1) xs
+  in  (x : ys, zs)
+
+-- The first item is an 'End'.
+getConstructedEndRepr' i (x@(End _, _):xs) =
+  let (ys, zs) = getConstructedEndRepr' (i - 1) xs
+  in  (x : ys, zs)
+
+-- The first item is not an 'End' or another 'Start'.
+getConstructedEndRepr' i (x : xs) =
+  let (ys, zs) = getConstructedEndRepr' i xs
+  in  (x : ys, zs)