asn1-data 0.6.1.2 → 0.6.1.3
raw patch · 2 files changed
+39/−2 lines, 2 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ Data.ASN1.BitArray: BitArrayOutOfBound :: Word64 -> BitArrayOutOfBound
+ Data.ASN1.BitArray: bitArrayClearBit :: BitArray -> Word64 -> BitArray
+ Data.ASN1.BitArray: bitArraySetBit :: BitArray -> Word64 -> BitArray
+ Data.ASN1.BitArray: bitArraySetBitValue :: BitArray -> Word64 -> Bool -> BitArray
+ Data.ASN1.BitArray: data BitArrayOutOfBound
+ Data.ASN1.BitArray: instance Eq BitArrayOutOfBound
+ Data.ASN1.BitArray: instance Exception BitArrayOutOfBound
+ Data.ASN1.BitArray: instance Show BitArrayOutOfBound
+ Data.ASN1.BitArray: instance Typeable BitArrayOutOfBound
Files
- Data/ASN1/BitArray.hs +38/−1
- asn1-data.cabal +1/−1
Data/ASN1/BitArray.hs view
@@ -1,15 +1,28 @@+{-# LANGUAGE DeriveDataTypeable #-} module Data.ASN1.BitArray ( BitArray(..)+ , BitArrayOutOfBound(..) , bitArrayLength , bitArrayGetBit+ , bitArraySetBitValue+ , bitArraySetBit+ , bitArrayClearBit , bitArrayGetData , toBitArray ) where import Data.Bits import Data.Word+import Data.Maybe import qualified Data.ByteString.Lazy as L+import Data.Typeable+import Control.Exception (Exception, throw) +-- | throwed in case of out of bounds in the bitarray.+data BitArrayOutOfBound = BitArrayOutOfBound Word64+ deriving (Show,Eq,Typeable)+instance Exception BitArrayOutOfBound+ -- | represent a bitarray / bitmap data BitArray = BitArray Word64 L.ByteString deriving (Show,Eq)@@ -18,12 +31,36 @@ bitArrayLength :: BitArray -> Word64 bitArrayLength (BitArray l _) = l +bitArrayOutOfBound :: Word64 -> a+bitArrayOutOfBound n = throw $ BitArrayOutOfBound n+ -- | get the nth bits bitArrayGetBit :: BitArray -> Word64 -> Bool bitArrayGetBit (BitArray l d) n- | n >= l = error ("array bit out of bounds: requesting bit " ++ show n ++ " but only got " ++ show l ++ " bits")+ | n >= l = bitArrayOutOfBound n | otherwise = flip testBit (7-fromIntegral bitn) $ L.index d (fromIntegral offset) where (offset, bitn) = n `divMod` 8++-- | set the nth bit to the value specified+bitArraySetBitValue :: BitArray -> Word64 -> Bool -> BitArray+bitArraySetBitValue (BitArray l d) n v+ | n >= l = bitArrayOutOfBound n+ | otherwise =+ let (before,after) = L.splitAt (fromIntegral offset) d in+ -- array bound check before prevent fromJust from failing.+ let (w,remaining) = fromJust $ L.uncons after in+ BitArray l (before `L.append` (setter w (fromIntegral bitn) `L.cons` remaining))+ where+ (offset, bitn) = n `divMod` 8+ setter = if v then setBit else clearBit++-- | set the nth bits+bitArraySetBit :: BitArray -> Word64 -> BitArray+bitArraySetBit bitarray n = bitArraySetBitValue bitarray n True++-- | clear the nth bits+bitArrayClearBit :: BitArray -> Word64 -> BitArray+bitArrayClearBit bitarray n = bitArraySetBitValue bitarray n False -- | get padded bytestring of the bitarray bitArrayGetData :: BitArray -> L.ByteString
asn1-data.cabal view
@@ -1,5 +1,5 @@ Name: asn1-data-Version: 0.6.1.2+Version: 0.6.1.3 Description: ASN1 data reader and writer in raw form with supports for high level forms of ASN1 (BER, CER and DER). .