packages feed

x509-ocsp 0.5.2.0 → 0.5.2.1

raw patch · 3 files changed

+86/−68 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

Changelog.md view
@@ -1,3 +1,8 @@+### 0.5.2.1++- Obtain signatures indirectly, via *bitArrayGetData*.+- Use more pattern synonyms internally to reach better readability.+ ### 0.5.2.0  - Use *getConstructedEndRepr* when the end of the sequence is required to be
Data/X509/OCSP.hs view
@@ -191,6 +191,26 @@                             | OCSPRespCertUnknown                             deriving (Show, Eq, Bounded, Enum) +pattern Asn1OCSPResponseEmpty :: OCSPResponseStatus -> [ASN1]+pattern Asn1OCSPResponseEmpty rst <-+    [ Start Sequence+    , Enumerated (toEnum . fromIntegral -> rst)+    , End Sequence+    ]++pattern Asn1OCSPResponseValue :: OCSPResponseStatus -> ByteString -> [ASN1]+pattern Asn1OCSPResponseValue rst val <-+    [ Start Sequence+    , Enumerated (toEnum . fromIntegral -> rst)+    , Start (Container Context 0)+    , Start Sequence+    , OID OidBasicOCSPResponse+    , OctetString val+    , End Sequence+    , End (Container Context 0)+    , End Sequence+    ]+ -- | Decode OCSP response. -- -- The value of the /certificate id/ is expected to be equal to what was@@ -204,57 +224,46 @@     -> L.ByteString             -- ^ Raw encoded OCSP response     -> Either ASN1Error (Maybe OCSPResponse) decodeOCSPResponse certId resp = decodeASN1 DER resp >>= \case-    [ Start Sequence-      , Enumerated (toEnum . fromIntegral -> v)-      , End Sequence-      ] -> Right $ Just $ OCSPResponse v Nothing-    [ Start Sequence-      , Enumerated (toEnum . fromIntegral -> v)-      , Start (Container Context 0)-      , Start Sequence-      , OID OidBasicOCSPResponse-      , OctetString resp'-      , End Sequence-      , End (Container Context 0)-      , End Sequence-      ] -> do-          pl <- decodeASN1' DER resp'-          Right $-              case pl of-                  Start Sequence-                    : Start Sequence-                    : Start (Container Context ctx)-                    : c1 | ctx `elem` [0..2] -> do-                        let skipVersion-                                | ctx == 0 = drop 1 . skipCurrentContainer-                                | otherwise = id-                        Just $ getCurrentContainerContents $-                            drop 2 $ skipCurrentContainer $ skipVersion c1-                  _ -> Nothing-              >>= \case-                      Start Sequence-                        : (fromASN1 -> Right (cId, c2)) | cId == certId ->-                            case c2 of-                                Other Context (toEnum -> n) _-                                  : c3 -> Just (n, c3)-                                Start (Container Context (toEnum -> n))-                                  : c3 -> Just (n, skipCurrentContainer c3)-                                _ -> Nothing-                      _ -> Nothing-              >>= \(n, tc1) -> case tc1 of-                                   tu@(ASN1Time TimeGeneralized _ _)-                                     : c4 -> Just (n, tu, c4)-                                   _ -> Nothing-              >>= \(st, tu, tc2) -> do-                  let nu = case tc2 of-                               Start (Container Context 0)-                                 : t@(ASN1Time TimeGeneralized _ _)-                                 : End (Container Context 0)-                                 : _ -> Just t-                               _ -> Nothing-                  Just $ OCSPResponse v $-                      Just $ OCSPResponsePayload-                          (OCSPResponseCertData st tu nu) pl+    Asn1OCSPResponseEmpty rst ->+        Right $ Just $ OCSPResponse rst Nothing+    Asn1OCSPResponseValue rst val -> do+        pl <- decodeASN1' DER val+        Right $+            case pl of+                Start Sequence+                  : Start Sequence+                  : Start (Container Context ctx)+                  : c1 | ctx `elem` [0..2] -> do+                      let skipVersion+                              | ctx == 0 = drop 1 . skipCurrentContainer+                              | otherwise = id+                      Just $ getCurrentContainerContents $+                          drop 2 $ skipCurrentContainer $ skipVersion c1+                _ -> Nothing+            >>= \case+                    Start Sequence+                      : (fromASN1 -> Right (cId, c2)) | cId == certId ->+                          case c2 of+                              Other Context (toEnum -> st) _+                                : c3 -> Just (st, c3)+                              Start (Container Context (toEnum -> st))+                                : c3 -> Just (st, skipCurrentContainer c3)+                              _ -> Nothing+                    _ -> Nothing+            >>= \(st, tc1) -> case tc1 of+                                  tu@(ASN1Time TimeGeneralized _ _)+                                    : c4 -> Just (st, tu, c4)+                                  _ -> Nothing+            >>= \(cst, tu, tc2) -> do+                let nu = case tc2 of+                             Start (Container Context 0)+                               : t@(ASN1Time TimeGeneralized _ _)+                               : End (Container Context 0)+                               : _ -> Just t+                             _ -> Nothing+                Just $ OCSPResponse rst $+                    Just $ OCSPResponsePayload+                        (OCSPResponseCertData cst tu nu) pl     _ -> Right Nothing  -- | Verification data from OCSP response payload.@@ -311,10 +320,15 @@ getOCSPResponseVerificationData     :: OCSPResponse             -- ^ OCSP response     -> Maybe OCSPResponseVerificationData-getOCSPResponseVerificationData (ocspRespPayload -> Just pl) =-    getOCSPResponseVerificationData' $ ocspRespASN1 pl-getOCSPResponseVerificationData _ = Nothing+getOCSPResponseVerificationData =+    ocspRespPayload >=> getOCSPResponseVerificationData' . ocspRespASN1 +pattern Asn1OCSPResponseCerts :: ASN1S+pattern Asn1OCSPResponseCerts certs <-+    Start (Container Context 0)+    : Start Sequence+    : certs@(Start Sequence : _)+ -- | Get verification data from OCSP response payload. -- -- This is a variant of 'getOCSPResponseVerificationData' that accepts the@@ -326,22 +340,21 @@ getOCSPResponseVerificationData' (Start Sequence : c1@(Start Sequence : _))     | (join bimap $ map fst -> (encodeASN1' DER -> resp, c2)) <-         getConstructedEndRepr $ map (, []) c1-    , Right (alg, BitString (BitArray _ sig) : c3) <- fromASN1 c2 =-        case c3 of-            [End Sequence] -> Just []-            _ | Start (Container Context 0)-                  : Start Sequence-                  : certs@(Start Sequence : _) <--                      getCurrentContainerContents c3 ->-                          reverse <$> collectCerts certs []-              | otherwise -> Nothing-        >>= Just . OCSPResponseVerificationData resp alg sig+    , Right (alg, BitString (bitArrayGetData -> sig) : c3) <-+        fromASN1 c2 =+            case c3 of+                [End Sequence] -> Just []+                (getCurrentContainerContents -> Asn1OCSPResponseCerts certs) ->+                    reverse <$> collectCerts certs []+                _ -> Nothing+            >>= Just . OCSPResponseVerificationData resp alg sig     where collectCerts (Start Sequence : c4) certs               | (c5@(Start Sequence : c6), next) <- getConstructedEnd 0 c4               , Right (cert, End Sequence : c7) <- fromASN1 c6-              , Right (alg, [BitString (BitArray _ sig)]) <- fromASN1 c7 =-                  collectCerts next $-                      (Signed cert alg sig, encodeASN1' DER c5) : certs+              , Right (alg, [BitString (bitArrayGetData -> sig)]) <-+                  fromASN1 c7 =+                      collectCerts next $+                          (Signed cert alg sig, encodeASN1' DER c5) : certs           collectCerts [End Sequence, End (Container Context 0)] certs =               Just certs           collectCerts _ _ =
x509-ocsp.cabal view
@@ -1,7 +1,7 @@ cabal-version:          2.4  name:                   x509-ocsp-version:                0.5.2.0+version:                0.5.2.1 synopsis:               Basic X509 OCSP implementation description:            Build X509 OCSP requests and parse responses homepage:               https://github.com/lyokha/x509-ocsp