Hello community, here is the log from the commit of package ghc-asn1-encoding for openSUSE:Factory checked in at 2019-10-18 14:33:40 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/ghc-asn1-encoding (Old) and /work/SRC/openSUSE:Factory/.ghc-asn1-encoding.new.2352 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "ghc-asn1-encoding" Fri Oct 18 14:33:40 2019 rev:11 rq:737190 version:0.9.6 Changes: -------- --- /work/SRC/openSUSE:Factory/ghc-asn1-encoding/ghc-asn1-encoding.changes 2018-10-25 08:22:21.583910956 +0200 +++ /work/SRC/openSUSE:Factory/.ghc-asn1-encoding.new.2352/ghc-asn1-encoding.changes 2019-10-18 14:33:41.640198678 +0200 @@ -1,0 +2,6 @@ +Mon Sep 30 02:01:31 UTC 2019 - psim...@suse.com + +- Update asn1-encoding to version 0.9.6. + Upstream does not provide a change log file. + +------------------------------------------------------------------- Old: ---- asn1-encoding-0.9.5.tar.gz New: ---- asn1-encoding-0.9.6.tar.gz asn1-encoding.cabal ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ ghc-asn1-encoding.spec ++++++ --- /var/tmp/diff_new_pack.MUqSWr/_old 2019-10-18 14:33:42.168197303 +0200 +++ /var/tmp/diff_new_pack.MUqSWr/_new 2019-10-18 14:33:42.172197293 +0200 @@ -1,7 +1,7 @@ # # spec file for package ghc-asn1-encoding # -# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -19,13 +19,14 @@ %global pkg_name asn1-encoding %bcond_with tests Name: ghc-%{pkg_name} -Version: 0.9.5 +Version: 0.9.6 Release: 0 Summary: ASN1 data reader and writer in RAW, BER and DER forms License: BSD-3-Clause Group: Development/Libraries/Haskell URL: https://hackage.haskell.org/package/%{pkg_name} Source0: https://hackage.haskell.org/package/%{pkg_name}-%{version}/%{pkg_name}-%{version}.tar.gz +Source1: https://hackage.haskell.org/package/%{pkg_name}-%{version}/revision/1.cabal#/%{pkg_name}.cabal BuildRequires: ghc-Cabal-devel BuildRequires: ghc-asn1-types-devel BuildRequires: ghc-bytestring-devel @@ -35,7 +36,6 @@ BuildRequires: ghc-mtl-devel BuildRequires: ghc-tasty-devel BuildRequires: ghc-tasty-quickcheck-devel -BuildRequires: ghc-text-devel %endif %description @@ -55,6 +55,7 @@ %prep %setup -q -n %{pkg_name}-%{version} +cp -p %{SOURCE1} %{pkg_name}.cabal %build %ghc_lib_build ++++++ asn1-encoding-0.9.5.tar.gz -> asn1-encoding-0.9.6.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/asn1-encoding-0.9.5/Data/ASN1/Get.hs new/asn1-encoding-0.9.6/Data/ASN1/Get.hs --- old/asn1-encoding-0.9.5/Data/ASN1/Get.hs 2016-06-07 06:53:07.000000000 +0200 +++ new/asn1-encoding-0.9.6/Data/ASN1/Get.hs 2019-09-29 20:41:04.000000000 +0200 @@ -16,6 +16,7 @@ -- case for asn1 and augmented by a position. -- {-# LANGUAGE Rank2Types #-} +{-# LANGUAGE CPP #-} module Data.ASN1.Get ( Result(..) , Input @@ -103,7 +104,10 @@ let ks' s1 b1 m1 p1 a = unGet (g a) s1 b1 m1 p1 kf ks in unGet m s0 b0 m0 p0 kf ks' - fail = failDesc +#if MIN_VERSION_base(4,13,0) +instance MonadFail Get where +#endif + fail = failDesc instance MonadPlus Get where mzero = failDesc "mzero" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/asn1-encoding-0.9.5/Data/ASN1/Prim.hs new/asn1-encoding-0.9.6/Data/ASN1/Prim.hs --- old/asn1-encoding-0.9.5/Data/ASN1/Prim.hs 2017-03-02 08:03:16.000000000 +0100 +++ new/asn1-encoding-0.9.6/Data/ASN1/Prim.hs 2019-06-23 15:18:23.000000000 +0200 @@ -8,6 +8,7 @@ -- Tools to read ASN1 primitive (e.g. boolean, int) -- +{-# LANGUAGE CPP #-} {-# LANGUAGE ViewPatterns #-} module Data.ASN1.Prim ( @@ -27,6 +28,7 @@ -- * marshall an ASN1 type from a val struct or a bytestring , getBoolean , getInteger + , getDouble , getBitString , getOctetString , getNull @@ -36,6 +38,7 @@ -- * marshall an ASN1 type to a bytestring , putTime , putInteger + , putDouble , putBitString , putString , putOID @@ -49,15 +52,18 @@ import Data.ASN1.Error import Data.ASN1.Serialize import Data.Bits +import Data.Monoid import Data.Word import Data.List (unfoldr) import Data.ByteString (ByteString) import Data.Char (ord, isDigit) import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as BC +import qualified Data.ByteString.Unsafe as B import Data.Hourglass -import Control.Applicative import Control.Arrow (first) +import Control.Applicative +import Control.Monad encodeHeader :: Bool -> ASN1Length -> ASN1 -> ASN1Header encodeHeader pc len (Boolean _) = ASN1Header Universal 0x1 pc len @@ -99,7 +105,7 @@ encodePrimitiveData (OctetString b) = putString b encodePrimitiveData Null = B.empty encodePrimitiveData (OID oidv) = putOID oidv -encodePrimitiveData (Real _) = B.empty -- not implemented +encodePrimitiveData (Real d) = putDouble d encodePrimitiveData (Enumerated i) = putInteger $ fromIntegral i encodePrimitiveData (ASN1String cs) = getCharacterStringRawData cs encodePrimitiveData (ASN1Time ty ti tz) = putTime ty ti tz @@ -164,7 +170,7 @@ decodePrimitive (ASN1Header Universal 0x6 _ _) p = getOID p decodePrimitive (ASN1Header Universal 0x7 _ _) _ = Left $ TypeNotImplemented "Object Descriptor" decodePrimitive (ASN1Header Universal 0x8 _ _) _ = Left $ TypeNotImplemented "External" -decodePrimitive (ASN1Header Universal 0x9 _ _) _ = Left $ TypeNotImplemented "real" +decodePrimitive (ASN1Header Universal 0x9 _ _) p = getDouble p decodePrimitive (ASN1Header Universal 0xa _ _) p = getEnumerated p decodePrimitive (ASN1Header Universal 0xb _ _) _ = Left $ TypeNotImplemented "EMBEDDED PDV" decodePrimitive (ASN1Header Universal 0xc _ _) p = getCharacterString UTF8 p @@ -219,6 +225,50 @@ v1 = s `B.index` 0 v2 = s `B.index` 1 +getDouble :: ByteString -> Either ASN1Error ASN1 +getDouble s = Real <$> getDoubleRaw s + +getDoubleRaw :: ByteString -> Either ASN1Error Double +getDoubleRaw s + | B.null s = Right 0 +getDoubleRaw s@(B.unsafeHead -> h) + | h == 0x40 = Right $! (1/0) -- Infinity + | h == 0x41 = Right $! (-1/0) -- -Infinity + | h == 0x42 = Right $! (0/0) -- NaN + | otherwise = do + let len = B.length s + base <- case (h `testBit` 5, h `testBit` 4) of + -- extract bits 5,4 for the base + (False, False) -> return 2 + (False, True) -> return 8 + (True, False) -> return 16 + _ -> Left . TypeDecodingFailed $ "real: invalid base detected" + -- check bit 6 for the sign + let mkSigned = if h `testBit` 6 then negate else id + -- extract bits 3,2 for the scaling factor + let scaleFactor = (h .&. 0x0c) `shiftR` 2 + expLength <- getExponentLength len h s + -- 1 byte for the header, expLength for the exponent, and at least 1 byte for the mantissa + unless (len > 1 + fromIntegral expLength) $ + Left . TypeDecodingFailed $ "real: not enough input for exponent and mantissa" + let (_, exp'') = intOfBytes $ B.unsafeTake (fromIntegral expLength) $ B.unsafeDrop 1 s + let exp' = case base :: Int of + 2 -> exp'' + 8 -> 3 * exp'' + _ -> 4 * exp'' -- must be 16 + exponent = exp' - fromIntegral scaleFactor + -- whatever is leftover is the mantissa, unsigned + (_, mantissa) = uintOfBytes $ B.unsafeDrop (1 + fromIntegral expLength) s + Right $! encodeFloat (mkSigned $ toInteger mantissa) (fromIntegral exponent) + +getExponentLength :: Int -> Word8 -> ByteString -> Either ASN1Error Word8 +getExponentLength len h s = + case h .&. 0x03 of + l | l == 0x03 -> do + unless (len > 1) $ Left . TypeDecodingFailed $ "real: not enough input to decode exponent length" + return $ B.unsafeIndex s 1 + | otherwise -> return $ l + 1 + getBitString :: ByteString -> Either ASN1Error ASN1 getBitString s = let toSkip = B.head s in @@ -362,3 +412,46 @@ where encode x | x == 0 = B.singleton 0 | otherwise = putVarEncodingIntegral x + +putDouble :: Double -> ByteString +putDouble d + | d == 0 = B.pack [] + | d == (1/0) = B.pack [0x40] + | d == negate (1/0) = B.pack [0x41] + | isNaN d = B.pack [0x42] + | otherwise = B.cons (header .|. (expLen - 1)) -- encode length of exponent + (expBS <> manBS) + where + (mkUnsigned, header) + | d < 0 = (negate, bINARY_NEGATIVE_NUMBER_ID) + | otherwise = (id, bINARY_POSITIVE_NUMBER_ID) + (man, exp) = decodeFloat d + (mantissa, exponent) = normalize (fromIntegral $ mkUnsigned man, exp) + expBS = putInteger (fromIntegral exponent) + expLen = fromIntegral (B.length expBS) + manBS = putInteger (fromIntegral mantissa) + +-- | Normalize the mantissa and adjust the exponent. +-- +-- DER requires the mantissa to either be 0 or odd, so we right-shift it +-- until the LSB is 1, and then add the shift amount to the exponent. +-- +-- TODO: handle denormal numbers +normalize :: (Word64, Int) -> (Word64, Int) +normalize (mantissa, exponent) = (mantissa `shiftR` sh, exponent + sh) + where + sh = countTrailingZeros mantissa + +#if !(MIN_VERSION_base(4,8,0)) + countTrailingZeros :: FiniteBits b => b -> Int + countTrailingZeros x = go 0 + where + go i | i >= w = i + | testBit x i = i + | otherwise = go (i+1) + w = finiteBitSize x +#endif + +bINARY_POSITIVE_NUMBER_ID, bINARY_NEGATIVE_NUMBER_ID :: Word8 +bINARY_POSITIVE_NUMBER_ID = 0x80 +bINARY_NEGATIVE_NUMBER_ID = 0xc0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/asn1-encoding-0.9.5/asn1-encoding.cabal new/asn1-encoding-0.9.6/asn1-encoding.cabal --- old/asn1-encoding-0.9.5/asn1-encoding.cabal 2017-03-02 08:06:48.000000000 +0100 +++ new/asn1-encoding-0.9.6/asn1-encoding.cabal 2019-09-29 21:06:37.000000000 +0200 @@ -1,5 +1,5 @@ Name: asn1-encoding -Version: 0.9.5 +Version: 0.9.6 Synopsis: ASN1 data reader and writer in RAW, BER and DER forms Description: ASN1 data reader and writer in raw form with supports for high level forms of ASN1 (BER, and DER). @@ -12,7 +12,7 @@ stability: experimental Build-Type: Simple Cabal-Version: >=1.10 -Homepage: http://github.com/vincenthz/hs-asn1 +Homepage: https://github.com/vincenthz/hs-asn1 Library Exposed-modules: Data.ASN1.Error @@ -21,8 +21,8 @@ Data.ASN1.Encoding Data.ASN1.Stream Data.ASN1.Object - other-modules: Data.ASN1.Prim - Data.ASN1.BinaryEncoding.Parse + Data.ASN1.Prim + other-modules: Data.ASN1.BinaryEncoding.Parse Data.ASN1.BinaryEncoding.Writer Data.ASN1.Internal Data.ASN1.Serialize @@ -40,7 +40,6 @@ Main-Is: Tests.hs Build-depends: base >= 3 && < 7 , bytestring - , text , mtl , tasty , tasty-quickcheck @@ -52,5 +51,5 @@ source-repository head type: git - location: git://github.com/vincenthz/hs-asn1 - subdir: asn1-encoding + location: https://github.com/vincenthz/hs-asn1 + subdir: encoding diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/asn1-encoding-0.9.5/tests/Tests.hs new/asn1-encoding-0.9.6/tests/Tests.hs --- old/asn1-encoding-0.9.5/tests/Tests.hs 2015-09-07 12:32:54.000000000 +0200 +++ new/asn1-encoding-0.9.6/tests/Tests.hs 2019-06-23 15:18:23.000000000 +0200 @@ -160,7 +160,7 @@ , liftM OctetString arbitrary , return Null , liftM OID arbitraryOID - --, Real Double + , liftM Real arbitrary -- , return Enumerated , ASN1String <$> arbitrary , ASN1Time <$> arbitrary <*> arbitrary <*> arbitrary @@ -192,15 +192,31 @@ prop_event_marshalling_id :: ASN1Events -> Bool prop_event_marshalling_id (ASN1Events e) = (parseLBS $ toLazyByteString e) == Right e +prop_asn1_der_marshalling_id :: [ASN1] -> Bool prop_asn1_der_marshalling_id v = (decodeASN1 DER . encodeASN1 DER) v `assertEq` Right v where assertEq got expected | got /= expected = error ("got: " ++ show got ++ " expected: " ++ show expected) | otherwise = True +prop_real_der_marshalling_id :: Double -> Bool +prop_real_der_marshalling_id v = (decodeASN1 DER . encodeASN1 DER) [Real v] `assertEq` Right [Real v] + where assertEq got expected + | got /= expected = error ("got: " ++ show got ++ " expected: " ++ show expected) + | otherwise = True + +prop_integral_real_der_marshalling_id :: Integer -> Bool +prop_integral_real_der_marshalling_id v = (decodeASN1 DER . encodeASN1 DER) [Real (fromInteger v)] + `assertEq` Right [Real (fromInteger v)] + where assertEq got expected + | got /= expected = error ("got: " ++ show got ++ " expected: " ++ show expected) + | otherwise = True + marshallingTests = testGroup "Marshalling" [ testProperty "Header" prop_header_marshalling_id , testProperty "Event" prop_event_marshalling_id , testProperty "DER" prop_asn1_der_marshalling_id + , testProperty "Real" prop_real_der_marshalling_id + , testProperty "Integral Real" prop_integral_real_der_marshalling_id ] main = defaultMain $ testGroup "asn1-encoding" [marshallingTests] ++++++ asn1-encoding.cabal ++++++ Name: asn1-encoding Version: 0.9.6 x-revision: 1 Synopsis: ASN1 data reader and writer in RAW, BER and DER forms Description: ASN1 data reader and writer in raw form with supports for high level forms of ASN1 (BER, and DER). License: BSD3 License-file: LICENSE Copyright: Vincent Hanquez <vinc...@snarc.org> Author: Vincent Hanquez <vinc...@snarc.org> Maintainer: vinc...@snarc.org Category: Data stability: experimental Build-Type: Simple Cabal-Version: >=1.10 Homepage: https://github.com/vincenthz/hs-asn1 Library Exposed-modules: Data.ASN1.Error Data.ASN1.BinaryEncoding Data.ASN1.BinaryEncoding.Raw Data.ASN1.Encoding Data.ASN1.Stream Data.ASN1.Object Data.ASN1.Prim other-modules: Data.ASN1.BinaryEncoding.Parse Data.ASN1.BinaryEncoding.Writer Data.ASN1.Internal Data.ASN1.Serialize Data.ASN1.Get Build-Depends: base >= 4.7 && < 5 , bytestring < 0.11 , hourglass >= 0.2.6 , asn1-types >= 0.3.0 && < 0.4 ghc-options: -Wall -fwarn-tabs Default-Language: Haskell2010 Test-Suite tests-asn1-encoding type: exitcode-stdio-1.0 hs-source-dirs: tests . Main-Is: Tests.hs Build-depends: base >= 3 && < 7 , bytestring , mtl , tasty , tasty-quickcheck , asn1-types , asn1-encoding , hourglass ghc-options: -Wall -fno-warn-orphans -fno-warn-missing-signatures Default-Language: Haskell2010 source-repository head type: git location: https://github.com/vincenthz/hs-asn1 subdir: encoding