Skip to content
  • ap@apple.com's avatar
    Use uint8_t vectors for WebCrypto data · f37f9b40
    ap@apple.com authored
    https://bugs.webkit.org/show_bug.cgi?id=124466
    
    Reviewed by Sam Weinig.
    
    Source/WebCore: 
    
    Using Vector<char> for crypto key data is somewhat non-idiomatic, and it gets simply
    dangerous for bignums, because signed arithmetic is not appropriate for bignum digits.
    
    * Modules/websockets/WebSocketHandshake.cpp:
    (WebCore::generateSecWebSocketKey):
    (WebCore::WebSocketHandshake::getExpectedWebSocketAccept):
    No longer need to cast data to char* here.
    
    * bindings/js/JSCryptoKeySerializationJWK.cpp:
    * bindings/js/JSCryptoKeySerializationJWK.h:
    * crypto/CryptoDigest.h:
    * crypto/CryptoKey.h:
    * crypto/keys/CryptoKeyAES.cpp:
    * crypto/keys/CryptoKeyAES.h:
    * crypto/keys/CryptoKeyDataOctetSequence.h:
    * crypto/keys/CryptoKeyDataRSAComponents.cpp:
    * crypto/keys/CryptoKeyDataRSAComponents.h:
    * crypto/keys/CryptoKeyHMAC.cpp:
    * crypto/keys/CryptoKeyHMAC.h:
    * crypto/keys/CryptoKeyRSA.h:
    * crypto/keys/CryptoKeySerializationRaw.cpp:
    * crypto/keys/CryptoKeySerializationRaw.h:
    * crypto/mac/CryptoAlgorithmAES_CBCMac.cpp:
    * crypto/mac/CryptoAlgorithmHMACMac.cpp:
    * crypto/mac/CryptoDigestMac.cpp:
    * crypto/mac/CryptoKeyMac.cpp:
    * crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h:
    Switched to Vector<uint8_t>.
    
    * crypto/mac/CryptoKeyRSAMac.cpp:
    (WebCore::getPublicKeyComponents): Extracted from buildAlgorithmDescription() and simplified.
    (WebCore::CryptoKeyRSA::create): Switched to Vector<uint8_t>.
    (WebCore::CryptoKeyRSA::buildAlgorithmDescription): No longer need to copy data just
    to change type from Vector<char> to Vector<unsigned char>.
    (WebCore::bigIntegerToUInt32): Ditto. No longer need to cast types when dealing with the bignum.
    (WebCore::CryptoKeyRSA::generatePair): Improved an error message a little.
    
    * fileapi/FileReaderLoader.cpp: (WebCore::FileReaderLoader::convertToDataURL):
    * inspector/DOMPatchSupport.cpp: (WebCore::DOMPatchSupport::createDigest):
    * inspector/InspectorPageAgent.cpp: (WebCore::InspectorPageAgent::archive):
    * platform/graphics/cg/ImageBufferCG.cpp: (WebCore::CGImageToDataURL):
    No longer need to cast data to char* here.
    
    Source/WTF: 
    
    Binary data can be UTF-8, in which case "char*" is idiomatic, or it can be arbitrary
    binary data, in which case "uint8_t*" is more common.
    
    Changed encode functions that took "const char *" to "const void*", and decode
    functions that took "Vector<char>&" now take an adapter class.
    
    The adapter relies on Vector<char> and Vector<uint8_t> classes having an identical layout.
    
    * wtf/text/Base64.cpp:
    (WTF::base64Encode):
    (WTF::base64URLEncode):
    (WTF::base64DecodeInternal):
    (WTF::base64Decode):
    (WTF::base64URLDecode):
    * wtf/text/Base64.h:
    (WTF::SignedOrUnsignedCharVectorAdapter):
    (WTF::ConstSignedOrUnsignedCharVectorAdapter):
    (WTF::base64Encode):
    (WTF::base64URLEncode):
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159390 268f45cc-cd09-0410-ab3c-d52691b4dbfc
    f37f9b40