Data.ASN1.BitArray: exported symbols usage examples

Symbols

  • bitArrayClearBit No usage example found for this symbol :( Collapse [-]
    bitArrayGetBit See 1 Occurences [+] Collapse [-]
    Found in Data.X509.Ext from the package x509
        ++ [End Sequence]
      where encodeAltName (AltNameRFC822 n) = [Other Context 1 $ BC.pack n]
            encodeAltName (AltNameDNS n)    = [Other Context 2 $ BC.pack n]
            encodeAltName (AltNameURI n)    = [Other Context 6 $ BC.pack n]
            encodeAltName (AltNameIP n)     = [Other Context 7 $ n]
            encodeAltName (AltNameXMPP n)   = [Start (Container Context 0),OID[1,3,6,1,5,5,7,8,5]
                                              ,Start (Container Context 0), ASN1String $ asn1CharacterString UTF8 n, End (Container Context 0)
                                              ,End (Container Context 0)]
            encodeAltName (AltNameDNSSRV n) = [Start (Container Context 0),OID[1,3,6,1,5,5,7,8,5]
                                              ,Start (Container Context 0), ASN1String $ asn1CharacterString UTF8 n, End (Container Context 0)
                                              ,End (Container Context 0)]
    
    bitsToFlags :: Enum a => BitArray -> [a]
    bitsToFlags bits = concat $ flip map [0..(bitArrayLength bits-1)] $ \i -> do
            let isSet = bitArrayGetBit bits i
            if isSet then [toEnum $ fromIntegral i] else []
    
    flagsToBits :: Enum a => [a] -> BitArray
    flagsToBits flags = foldl bitArraySetBit bitArrayEmpty $ map (fromIntegral . fromEnum) flags
      where bitArrayEmpty = toBitArray (B.pack [0,0]) 7
    

    bitArrayGetData See 8 Occurences [+] Collapse [-]
    Found in Data.ASN1.Pretty from the package asn1-types
        prettyPrint n (x@(Start _) : xs) = indent n     ++ p id x ++ prettyPrint (n+1) xs
        prettyPrint n (x@(End _) : xs)   = indent (n-1) ++ p id x ++ prettyPrint (n-1) xs
        prettyPrint n (x : xs)           = indent n     ++ p id x ++ prettyPrint n xs
    
    pretty SingleLine = prettyPrint
      where
        prettyPrint []                 = ""
        prettyPrint (x@(Start _) : xs) = p id x ++ "," ++ prettyPrint xs
        prettyPrint (x@(End _) : xs)   = p id x ++ "," ++ prettyPrint xs
        prettyPrint (x : xs)           = p id x ++ "," ++ prettyPrint xs
    
    p :: ([Char] -> t) -> ASN1 -> t
    p put (Boolean b)                        = put ("bool: " ++ show b)
    p put (IntVal i)                         = put ("int: " ++ showHex i "")
    p put (BitString bits)                   = put ("bitstring: " ++ (hexdump $ bitArrayGetData bits))
    p put (OctetString bs)                   = put ("octetstring: " ++ hexdump bs)
    p put (Null)                             = put "null"
    p put (OID is)                           = put ("OID: " ++ show is)
    p put (Real d)                           = put ("real: " ++ show d)
    p put (Enumerated _)                     = put "enum"
    

    Found in Data.X509.PKCS10 from the package pkcs10
                        (CertificationRequest cri <$> getObject <*> getObject)
          f (Right (req, End Sequence : xs')) =
            Right (req, xs')
          f (Right _) = Left "fromASN1: PKCS9.CertificationRequest: unknown format"
          f (Left e) = Left e
    
    parseSignedCertificationRequest _ =
      Left "fromASN1: PKCS9.CertificationRequest: unknown format"
    
    instance ASN1Object Signature where
      toASN1 (Signature bs) xs =
        (BitString $ toBitArray bs 0) : xs
    
      fromASN1 (BitString s : xs) =
        Right (Signature $ bitArrayGetData s, xs)
    
      fromASN1 _ = Left "fromASN1: PKCS9.Signature: unknown format"
    
    instance ASN1Object CertificationRequestInfo where
      toASN1 (CertificationRequestInfo version subject pubKey attributes) xs =
    

    Found in Data.X509.PublicKey from the package x509
                            , pubkeyEC_cofactor  = cofactor
                            , pubkeyEC_seed      = os2ip $ bitArrayGetData seed
                            }, xs2)
                    _ ->
                        Left $ "fromASN1: X509.PubKey: unknown EC format: " ++ show xs
            | otherwise = Left $ "fromASN1: unknown public key OID: " ++ show pkalg
          where decodeASN1Err format bits xs2 f =
                    case decodeASN1' BER (bitArrayGetData bits) of
                        Left err -> Left ("fromASN1: X509.PubKey " ++ format ++ " bitarray cannot be parsed: " ++ show err)
                        Right s  -> case f s of
                                        Left err -> Left err
                                        Right (r, xsinner) -> Right (r, xsinner ++ xs2)
                toPubKeyRSA = either Left (\(rsaKey, r) -> Right (PubKeyRSA rsaKey, r))
    
                bitArrayToPoint = SerializedPoint . bitArrayGetData
    
                removeNull (Null:r) = r
                removeNull l        = l
    
        fromASN1 l = Left ("fromASN1: X509.PubKey: unknown format:" ++ show l)
    

    Found in Data.X509.PublicKey from the package x509
                        Right (PubKeyEC $ PubKeyEC_Prime
                            { pubkeyEC_pub       = bitArrayToPoint pub
                            , pubkeyEC_a         = os2ip a
                            , pubkeyEC_b         = os2ip b
                            , pubkeyEC_prime     = prime
                            , pubkeyEC_generator = SerializedPoint generator
                            , pubkeyEC_order     = order
                            , pubkeyEC_cofactor  = cofactor
                            , pubkeyEC_seed      = os2ip $ bitArrayGetData seed
                            }, xs2)
                    _ ->
                        Left $ "fromASN1: X509.PubKey: unknown EC format: " ++ show xs
            | otherwise = Left $ "fromASN1: unknown public key OID: " ++ show pkalg
          where decodeASN1Err format bits xs2 f =
                    case decodeASN1' BER (bitArrayGetData bits) of
                        Left err -> Left ("fromASN1: X509.PubKey " ++ format ++ " bitarray cannot be parsed: " ++ show err)
                        Right s  -> case f s of
                                        Left err -> Left err
                                        Right (r, xsinner) -> Right (r, xsinner ++ xs2)
                toPubKeyRSA = either Left (\(rsaKey, r) -> Right (PubKeyRSA rsaKey, r))
    

    Found in Data.X509.PublicKey from the package x509
                        :IntVal cofactor
                        :End Sequence
                        :End Sequence
                        :BitString pub
                        :End Sequence
                        :xs2 ->
                        Right (PubKeyEC $ PubKeyEC_Prime
                            { pubkeyEC_pub       = bitArrayToPoint pub
                            , pubkeyEC_a         = os2ip a
                            , pubkeyEC_b         = os2ip b
                            , pubkeyEC_prime     = prime
                            , pubkeyEC_generator = SerializedPoint generator
                            , pubkeyEC_order     = order
                            , pubkeyEC_cofactor  = cofactor
                            , pubkeyEC_seed      = os2ip $ bitArrayGetData seed
                            }, xs2)
                    _ ->
                        Left $ "fromASN1: X509.PubKey: unknown EC format: " ++ show xs
            | otherwise = Left $ "fromASN1: unknown public key OID: " ++ show pkalg
          where decodeASN1Err format bits xs2 f =
    

    Found in Data.X509.PrivateKey from the package x509
              where
                failure = Left $ failing $ "unknown curve " ++ show oid_
                success = Right . flip PrivKeyEC_Named d
                mcurve = lookupByOID curvesOIDTable oid_
            subgo (Start Sequence : IntVal 1 : Start Sequence
                : OID [1, 2, 840, 10045, 1, 1] : IntVal p : End Sequence
                : Start Sequence : OctetString a : OctetString b : BitString s
                : End Sequence : OctetString g : IntVal o : IntVal c
                : End Sequence : _) =
                    pure $ PrivKeyEC_Prime d a' b' p g' o c s'
              where
                a' = os2ip a
                b' = os2ip b
                g' = SerializedPoint g
                s' = os2ip $ bitArrayGetData s
            subgo (Null : rest_) = subgo rest_
            subgo [] = Left $ failing "curve is missing"
            subgo _ = Left $ failing "unexpected curve format"
        go acc (Start Sequence : IntVal 0 : Start Sequence
            : OID [1, 2, 840, 10045, 2, 1] : rest) = case rest' of
    

    Found in Data.X509.Signed from the package x509
            parseSigned l = onContainer (fst $ getConstructedEndRepr l) $ \l2 ->
                let (objRepr,rem1)   = getConstructedEndRepr l2
                    (sigAlgSeq,rem2) = getConstructedEndRepr rem1
                    (sigSeq,_)       = getConstructedEndRepr rem2
                    obj              = onContainer objRepr (either Left Right . fromASN1 . map fst)
                 in case (obj, map fst sigSeq) of
                        (Right (o,[]), [BitString signature]) ->
                            let rawObj = Raw.toByteString $ concatMap snd objRepr
                             in case fromASN1 $ map fst sigAlgSeq of
                                    Left s           -> Left ("signed object error sigalg: " ++ s)
                                    Right (sigAlg,_) ->
                                        let signed = Signed
                                                        { signedObject    = o
                                                        , signedAlg       = sigAlg
                                                        , signedSignature = bitArrayGetData signature
                                                        }
                                         in Right $ SignedExact
                                                    { getSigned          = signed
                                                    , exactObjectRaw     = rawObj
                                                    , encodeSignedObject = b
    

    Found in Data.X509.Memory from the package x509-store
                    : End Sequence
                    : OctetString generator
                    : IntVal order
                    : IntVal cofactor
                    : End Sequence
                    : _)              =
        Right X509.PrivKeyEC_Prime
                  { X509.privkeyEC_priv      = d
                  , X509.privkeyEC_a         = os2ip a
                  , X509.privkeyEC_b         = os2ip b
                  , X509.privkeyEC_prime     = prime
                  , X509.privkeyEC_generator = X509.SerializedPoint generator
                  , X509.privkeyEC_order     = order
                  , X509.privkeyEC_cofactor  = cofactor
                  , X509.privkeyEC_seed      = os2ip $ bitArrayGetData seed
                  }
    getPrivKeyEC _ _                  = Left "ecdsaFromASN1: unexpected curve format"
    
    containerWithTag :: ASN1Tag -> [ASN1] -> ([ASN1], [ASN1])
    containerWithTag etag (Start (Container _ atag) : xs)
    

    bitArrayLength See 1 Occurences [+] Collapse [-]
    Found in Data.X509.Ext from the package x509
        ++ concatMap encodeAltName names
        ++ [End Sequence]
      where encodeAltName (AltNameRFC822 n) = [Other Context 1 $ BC.pack n]
            encodeAltName (AltNameDNS n)    = [Other Context 2 $ BC.pack n]
            encodeAltName (AltNameURI n)    = [Other Context 6 $ BC.pack n]
            encodeAltName (AltNameIP n)     = [Other Context 7 $ n]
            encodeAltName (AltNameXMPP n)   = [Start (Container Context 0),OID[1,3,6,1,5,5,7,8,5]
                                              ,Start (Container Context 0), ASN1String $ asn1CharacterString UTF8 n, End (Container Context 0)
                                              ,End (Container Context 0)]
            encodeAltName (AltNameDNSSRV n) = [Start (Container Context 0),OID[1,3,6,1,5,5,7,8,5]
                                              ,Start (Container Context 0), ASN1String $ asn1CharacterString UTF8 n, End (Container Context 0)
                                              ,End (Container Context 0)]
    
    bitsToFlags :: Enum a => BitArray -> [a]
    bitsToFlags bits = concat $ flip map [0..(bitArrayLength bits-1)] $ \i -> do
            let isSet = bitArrayGetBit bits i
            if isSet then [toEnum $ fromIntegral i] else []
    
    flagsToBits :: Enum a => [a] -> BitArray
    flagsToBits flags = foldl bitArraySetBit bitArrayEmpty $ map (fromIntegral . fromEnum) flags
    

    bitArraySetBit See 1 Occurences [+] Collapse [-]
    Found in Data.X509.Ext from the package x509
            encodeAltName (AltNameIP n)     = [Other Context 7 $ n]
            encodeAltName (AltNameXMPP n)   = [Start (Container Context 0),OID[1,3,6,1,5,5,7,8,5]
                                              ,Start (Container Context 0), ASN1String $ asn1CharacterString UTF8 n, End (Container Context 0)
                                              ,End (Container Context 0)]
            encodeAltName (AltNameDNSSRV n) = [Start (Container Context 0),OID[1,3,6,1,5,5,7,8,5]
                                              ,Start (Container Context 0), ASN1String $ asn1CharacterString UTF8 n, End (Container Context 0)
                                              ,End (Container Context 0)]
    
    bitsToFlags :: Enum a => BitArray -> [a]
    bitsToFlags bits = concat $ flip map [0..(bitArrayLength bits-1)] $ \i -> do
            let isSet = bitArrayGetBit bits i
            if isSet then [toEnum $ fromIntegral i] else []
    
    flagsToBits :: Enum a => [a] -> BitArray
    flagsToBits flags = foldl bitArraySetBit bitArrayEmpty $ map (fromIntegral . fromEnum) flags
      where bitArrayEmpty = toBitArray (B.pack [0,0]) 7
    
    data ExtNetscapeComment = ExtNetscapeComment B.ByteString
        deriving (Show,Eq)
    

    bitArraySetBitValue No usage example found for this symbol :( Collapse [-]
    toBitArray See 8 Occurences [+] Collapse [-]
    Found in Data.ASN1.Prim from the package asn1-encoding
        | otherwise       =
            if (v1 == 0xff && testBit v2 7) || (v1 == 0x0 && (not $ testBit v2 7))
                then Left . TypeDecodingFailed $ typestr ++ ": not shortest encoding"
                else Right $ snd $ intOfBytes s
            where
                v1 = s `B.index` 0
                v2 = s `B.index` 1
    
    getBitString :: ByteString -> Either ASN1Error ASN1
    getBitString s =
        let toSkip = B.head s in
        let toSkip' = if toSkip >= 48 && toSkip <= 48 + 7 then toSkip - (fromIntegral $ ord '0') else toSkip in
        let xs = B.tail s in
        if toSkip' >= 0 && toSkip' <= 7
            then Right $ BitString $ toBitArray xs (fromIntegral toSkip')
            else Left $ TypeDecodingFailed ("bitstring: skip number not within bound " ++ show toSkip' ++ " " ++  show s)
    
    getCharacterString :: ASN1StringEncoding -> ByteString -> Either ASN1Error ASN1
    getCharacterString encoding bs = Right $ ASN1String (ASN1CharacterString encoding bs)
    

    Found in Data.X509.PKCS10 from the package pkcs10
                  raw = encodeASN1' DER $ take (length xs' - length rest) xs'
              Left e -> Left e
          p cri raw = (flip SignedCertificationRequest raw) <$>
                        (CertificationRequest cri <$> getObject <*> getObject)
          f (Right (req, End Sequence : xs')) =
            Right (req, xs')
          f (Right _) = Left "fromASN1: PKCS9.CertificationRequest: unknown format"
          f (Left e) = Left e
    
    parseSignedCertificationRequest _ =
      Left "fromASN1: PKCS9.CertificationRequest: unknown format"
    
    instance ASN1Object Signature where
      toASN1 (Signature bs) xs =
        (BitString $ toBitArray bs 0) : xs
    
      fromASN1 (BitString s : xs) =
        Right (Signature $ bitArrayGetData s, xs)
    
      fromASN1 _ = Left "fromASN1: PKCS9.Signature: unknown format"
    

    Found in Data.X509.PublicKey from the package x509
                                            ,IntVal (DSA.params_q params)
                                            ,IntVal (DSA.params_g params)]
            params = DSA.public_params pubkey
            bits   = encodeASN1' DER [IntVal $ DSA.public_y pubkey]
        encodeInner (PubKeyEC (PubKeyEC_Named curveName (SerializedPoint bits))) =
            asn1Container Sequence [pkalg,OID eOid] ++ [BitString $ toBitArray bits 0]
          where
            eOid = case lookupOID curvesOIDTable curveName of
                        Just oid -> oid
                        _        -> error ("undefined curve OID: " ++ show curveName)
        encodeInner (PubKeyEC (PubKeyEC_Prime {})) =
            error "encodeInner: unimplemented public key EC_Prime"
        encodeInner (PubKeyDH _) = error "encodeInner: unimplemented public key DH"
        encodeInner (PubKeyUnknown _ l) =
            asn1Container Sequence [pkalg,Null] ++ [BitString $ toBitArray l 0]
    
    rsaPubToASN1 :: RSA.PublicKey -> [ASN1] -> [ASN1]
    rsaPubToASN1 pubkey xs =
        Start Sequence : IntVal (RSA.public_n pubkey) : IntVal (RSA.public_e pubkey) : End Sequence : xs
    

    Found in Data.X509.PublicKey from the package x509
      where
        pkalg = OID $ getObjectID $ pubkeyToAlg key
        encodeInner (PubKeyRSA pubkey) =
            asn1Container Sequence [pkalg,Null] ++ [BitString $ toBitArray bits 0]
          where bits = encodeASN1' DER $ rsaPubToASN1 pubkey []
        encodeInner (PubKeyDSA pubkey) =
            asn1Container Sequence ([pkalg] ++ dsaseq) ++ [BitString $ toBitArray bits 0]
          where
            dsaseq = asn1Container Sequence [IntVal (DSA.params_p params)
                                            ,IntVal (DSA.params_q params)
                                            ,IntVal (DSA.params_g params)]
            params = DSA.public_params pubkey
            bits   = encodeASN1' DER [IntVal $ DSA.public_y pubkey]
        encodeInner (PubKeyEC (PubKeyEC_Named curveName (SerializedPoint bits))) =
            asn1Container Sequence [pkalg,OID eOid] ++ [BitString $ toBitArray bits 0]
          where
            eOid = case lookupOID curvesOIDTable curveName of
                        Just oid -> oid
                        _        -> error ("undefined curve OID: " ++ show curveName)
        encodeInner (PubKeyEC (PubKeyEC_Prime {})) =
    

    Found in Data.X509.PublicKey from the package x509
    pubkeyToAlg (PubKeyRSA _)         = PubKeyALG_RSA
    pubkeyToAlg (PubKeyDSA _)         = PubKeyALG_DSA
    pubkeyToAlg (PubKeyDH _)          = PubKeyALG_DH
    pubkeyToAlg (PubKeyEC _)          = PubKeyALG_EC
    pubkeyToAlg (PubKeyUnknown oid _) = PubKeyALG_Unknown oid
    
    encodePK :: PubKey -> [ASN1]
    encodePK key = asn1Container Sequence (encodeInner key)
      where
        pkalg = OID $ getObjectID $ pubkeyToAlg key
        encodeInner (PubKeyRSA pubkey) =
            asn1Container Sequence [pkalg,Null] ++ [BitString $ toBitArray bits 0]
          where bits = encodeASN1' DER $ rsaPubToASN1 pubkey []
        encodeInner (PubKeyDSA pubkey) =
            asn1Container Sequence ([pkalg] ++ dsaseq) ++ [BitString $ toBitArray bits 0]
          where
            dsaseq = asn1Container Sequence [IntVal (DSA.params_p params)
                                            ,IntVal (DSA.params_q params)
                                            ,IntVal (DSA.params_g params)]
            params = DSA.public_params pubkey
    

    Found in Data.X509.PublicKey from the package x509
    -- | Convert a Public key to the Public Key Algorithm type
    pubkeyToAlg :: PubKey -> PubKeyALG
    pubkeyToAlg (PubKeyRSA _)         = PubKeyALG_RSA
    pubkeyToAlg (PubKeyDSA _)         = PubKeyALG_DSA
    pubkeyToAlg (PubKeyDH _)          = PubKeyALG_DH
    pubkeyToAlg (PubKeyEC _)          = PubKeyALG_EC
    pubkeyToAlg (PubKeyUnknown oid _) = PubKeyALG_Unknown oid
    
    encodePK :: PubKey -> [ASN1]
    encodePK key = asn1Container Sequence (encodeInner key)
      where
        pkalg = OID $ getObjectID $ pubkeyToAlg key
        encodeInner (PubKeyRSA pubkey) =
            asn1Container Sequence [pkalg,Null] ++ [BitString $ toBitArray bits 0]
          where bits = encodeASN1' DER $ rsaPubToASN1 pubkey []
        encodeInner (PubKeyDSA pubkey) =
            asn1Container Sequence ([pkalg] ++ dsaseq) ++ [BitString $ toBitArray bits 0]
          where
            dsaseq = asn1Container Sequence [IntVal (DSA.params_p params)
    

    Found in Data.X509.Ext from the package x509
            encodeAltName (AltNameXMPP n)   = [Start (Container Context 0),OID[1,3,6,1,5,5,7,8,5]
                                              ,Start (Container Context 0), ASN1String $ asn1CharacterString UTF8 n, End (Container Context 0)
                                              ,End (Container Context 0)]
            encodeAltName (AltNameDNSSRV n) = [Start (Container Context 0),OID[1,3,6,1,5,5,7,8,5]
                                              ,Start (Container Context 0), ASN1String $ asn1CharacterString UTF8 n, End (Container Context 0)
                                              ,End (Container Context 0)]
    
    bitsToFlags :: Enum a => BitArray -> [a]
    bitsToFlags bits = concat $ flip map [0..(bitArrayLength bits-1)] $ \i -> do
            let isSet = bitArrayGetBit bits i
            if isSet then [toEnum $ fromIntegral i] else []
    
    flagsToBits :: Enum a => [a] -> BitArray
    flagsToBits flags = foldl bitArraySetBit bitArrayEmpty $ map (fromIntegral . fromEnum) flags
      where bitArrayEmpty = toBitArray (B.pack [0,0]) 7
    
    data ExtNetscapeComment = ExtNetscapeComment B.ByteString
        deriving (Show,Eq)
    
    instance Extension ExtNetscapeComment where
    

    Found in Data.X509.Signed from the package x509
    objectToSignedExactF :: (Functor f, Show a, Eq a, ASN1Object a)
                         => (ByteString -> f (ByteString, SignatureALG)) -- ^ signature function
                         -> a                                            -- ^ object to sign
                         -> f (SignedExact a)
    objectToSignedExactF signatureFunction object = fmap buildSignedExact (signatureFunction objRaw)
      where buildSignedExact (sigBits,sigAlg) =
                let signed     = Signed { signedObject    = object
                                        , signedAlg       = sigAlg
                                        , signedSignature = sigBits
                                        }
                    signedRaw  = encodeASN1' DER signedASN1
                    signedASN1 = Start Sequence
                                   : objASN1
                                   (toASN1 sigAlg
                                   (BitString (toBitArray sigBits 0)
                               : End Sequence
                               : []))
                in SignedExact signed objRaw signedRaw
            objASN1            = \xs -> Start Sequence : toASN1 object (End Sequence : xs)
            objRaw             = encodeASN1' DER (objASN1 [])
    

    BitArray No usage example found for this symbol :( Collapse [-]
    BitArrayOutOfBound No usage example found for this symbol :( Collapse [-]