Title: [158363] trunk/Source/WebCore
Revision
158363
Author
[email protected]
Date
2013-10-31 10:13:49 -0700 (Thu, 31 Oct 2013)

Log Message

Add a crypto algorithm abstraction
https://bugs.webkit.org/show_bug.cgi?id=123474

Reviewed by Sam Weinig.

This works slightly differently than WebCrypto implies. We have separate classes
for algorithm and its parameters, while WebCrypto puts them in the same dictionary.

* WebCore.xcodeproj/project.pbxproj: Added new files.

* crypto/CryptoAlgorithm.cpp: Added. As most algorithms don't implement most
operations, default implementations just raise an exception.
* crypto/CryptoAlgorithm.h: Added.

* crypto/CryptoAlgorithmParameters.h: Added. Base class for numerous future parameter
dictionaries, such as HmacParams or HmacKeyParams.

* crypto/CryptoAlgorithmRegistry.cpp: Added.
* crypto/CryptoAlgorithmRegistry.h: Added.
The registry decouples universal bindings code from algorithms that may or may not
be implemented on each platform.

* crypto/mac: Added.
* crypto/mac/CryptoAlgorithmRegistryMac.cpp: Added.
(WebCore::CryptoAlgorithmRegistry::platformRegisterAlgorithms): Algorithms implemented
on Mac will be registered by this function.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (158362 => 158363)


--- trunk/Source/WebCore/ChangeLog	2013-10-31 16:50:03 UTC (rev 158362)
+++ trunk/Source/WebCore/ChangeLog	2013-10-31 17:13:49 UTC (rev 158363)
@@ -1,5 +1,34 @@
 2013-10-31  Alexey Proskuryakov  <[email protected]>
 
+        Add a crypto algorithm abstraction
+        https://bugs.webkit.org/show_bug.cgi?id=123474
+
+        Reviewed by Sam Weinig.
+
+        This works slightly differently than WebCrypto implies. We have separate classes
+        for algorithm and its parameters, while WebCrypto puts them in the same dictionary.
+
+        * WebCore.xcodeproj/project.pbxproj: Added new files.
+
+        * crypto/CryptoAlgorithm.cpp: Added. As most algorithms don't implement most
+        operations, default implementations just raise an exception.
+        * crypto/CryptoAlgorithm.h: Added.
+
+        * crypto/CryptoAlgorithmParameters.h: Added. Base class for numerous future parameter
+        dictionaries, such as HmacParams or HmacKeyParams.
+
+        * crypto/CryptoAlgorithmRegistry.cpp: Added.
+        * crypto/CryptoAlgorithmRegistry.h: Added.
+        The registry decouples universal bindings code from algorithms that may or may not
+        be implemented on each platform.
+
+        * crypto/mac: Added.
+        * crypto/mac/CryptoAlgorithmRegistryMac.cpp: Added.
+        (WebCore::CryptoAlgorithmRegistry::platformRegisterAlgorithms): Algorithms implemented
+        on Mac will be registered by this function.
+
+2013-10-31  Alexey Proskuryakov  <[email protected]>
+
         REGRESSION(r158333): http/tests/xmlhttprequest/response-encoding.html and xmlhttprequest-overridemimetype-content-type-header.html are failing
         https://bugs.webkit.org/show_bug.cgi?id=123548
 

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (158362 => 158363)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2013-10-31 16:50:03 UTC (rev 158362)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2013-10-31 17:13:49 UTC (rev 158363)
@@ -5552,6 +5552,9 @@
 		E16982601134636A00894115 /* ObjCRuntimeObject.mm in Sources */ = {isa = PBXBuildFile; fileRef = E169825F1134636A00894115 /* ObjCRuntimeObject.mm */; };
 		E16A84F914C85CCC002977DF /* CSSBorderImage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E16A84F714C85CCC002977DF /* CSSBorderImage.cpp */; };
 		E16A84FA14C85CCC002977DF /* CSSBorderImage.h in Headers */ = {isa = PBXBuildFile; fileRef = E16A84F814C85CCC002977DF /* CSSBorderImage.h */; };
+		E172AF6D180F24C600FBADB9 /* CryptoAlgorithm.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E172AF6B180F24C600FBADB9 /* CryptoAlgorithm.cpp */; };
+		E172AF6E180F24C600FBADB9 /* CryptoAlgorithm.h in Headers */ = {isa = PBXBuildFile; fileRef = E172AF6C180F24C600FBADB9 /* CryptoAlgorithm.h */; };
+		E172AF74180F352500FBADB9 /* CryptoAlgorithmRegistryMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E172AF72180F352500FBADB9 /* CryptoAlgorithmRegistryMac.cpp */; };
 		E172AF8F1811BC3700FBADB9 /* JSDOMPromise.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E172AF8D1811BC3700FBADB9 /* JSDOMPromise.cpp */; };
 		E172AF901811BC3700FBADB9 /* JSDOMPromise.h in Headers */ = {isa = PBXBuildFile; fileRef = E172AF8E1811BC3700FBADB9 /* JSDOMPromise.h */; };
 		E172AF70180F289500FBADB9 /* CryptoKeyUsage.h in Headers */ = {isa = PBXBuildFile; fileRef = E172AF6F180F289500FBADB9 /* CryptoKeyUsage.h */; };
@@ -5618,6 +5621,7 @@
 		E1C416170F6563180092D2FB /* CrossOriginAccessControl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1C416160F6563180092D2FB /* CrossOriginAccessControl.cpp */; };
 		E1C4DE690EA75C1E0023CCD6 /* ActiveDOMObject.h in Headers */ = {isa = PBXBuildFile; fileRef = E1C4DE680EA75C1E0023CCD6 /* ActiveDOMObject.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E1C4DE6E0EA75C650023CCD6 /* ActiveDOMObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1C4DE6D0EA75C650023CCD6 /* ActiveDOMObject.cpp */; };
+		E1C657271816F9FE00256CDD /* CryptoAlgorithmParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = E1C657261816F9FE00256CDD /* CryptoAlgorithmParameters.h */; };
 		E1C657251816E69D00256CDD /* CryptoAlgorithmIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = E1C657241816E69D00256CDD /* CryptoAlgorithmIdentifier.h */; };
 		E1C8BE5D0E8BD15A0064CB7D /* JSWorker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1C8BE5C0E8BD15A0064CB7D /* JSWorker.cpp */; };
 		E1CA5CBC0E8CDCAF00E8EF90 /* JSWorkerCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1CA5CBB0E8CDCAF00E8EF90 /* JSWorkerCustom.cpp */; };
@@ -5640,6 +5644,8 @@
 		E1FF8F64180745D800132674 /* JSSubtleCrypto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1FF8F62180745D800132674 /* JSSubtleCrypto.cpp */; };
 		E1FF8F65180745D800132674 /* JSSubtleCrypto.h in Headers */ = {isa = PBXBuildFile; fileRef = E1FF8F63180745D800132674 /* JSSubtleCrypto.h */; };
 		E1FF8F681807460800132674 /* JSSubtleCryptoCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1FF8F661807460800132674 /* JSSubtleCryptoCustom.cpp */; };
+		E1FF8F6C180DB5BE00132674 /* CryptoAlgorithmRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1FF8F6A180DB5BE00132674 /* CryptoAlgorithmRegistry.cpp */; };
+		E1FF8F6D180DB5BE00132674 /* CryptoAlgorithmRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = E1FF8F6B180DB5BE00132674 /* CryptoAlgorithmRegistry.h */; };
 		E401C27517CE53EC00C41A35 /* ElementIteratorAssertions.h in Headers */ = {isa = PBXBuildFile; fileRef = E401C27417CE53EC00C41A35 /* ElementIteratorAssertions.h */; };
 		E4295FA412B0614E00D1ACE0 /* ResourceLoadPriority.h in Headers */ = {isa = PBXBuildFile; fileRef = E4295FA312B0614E00D1ACE0 /* ResourceLoadPriority.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E43105B816750F0C00DB2FB8 /* NodeTraversal.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43105B716750F0C00DB2FB8 /* NodeTraversal.cpp */; };
@@ -12550,6 +12556,9 @@
 		E169825F1134636A00894115 /* ObjCRuntimeObject.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ObjCRuntimeObject.mm; sourceTree = "<group>"; };
 		E16A84F714C85CCC002977DF /* CSSBorderImage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSBorderImage.cpp; sourceTree = "<group>"; };
 		E16A84F814C85CCC002977DF /* CSSBorderImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSBorderImage.h; sourceTree = "<group>"; };
+		E172AF6B180F24C600FBADB9 /* CryptoAlgorithm.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoAlgorithm.cpp; sourceTree = "<group>"; };
+		E172AF6C180F24C600FBADB9 /* CryptoAlgorithm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithm.h; sourceTree = "<group>"; };
+		E172AF72180F352500FBADB9 /* CryptoAlgorithmRegistryMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CryptoAlgorithmRegistryMac.cpp; path = mac/CryptoAlgorithmRegistryMac.cpp; sourceTree = "<group>"; };
 		E172AF8D1811BC3700FBADB9 /* JSDOMPromise.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMPromise.cpp; sourceTree = "<group>"; };
 		E172AF8E1811BC3700FBADB9 /* JSDOMPromise.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMPromise.h; sourceTree = "<group>"; };
 		E172AF6F180F289500FBADB9 /* CryptoKeyUsage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoKeyUsage.h; sourceTree = "<group>"; };
@@ -12625,6 +12634,7 @@
 		E1C416160F6563180092D2FB /* CrossOriginAccessControl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CrossOriginAccessControl.cpp; sourceTree = "<group>"; };
 		E1C4DE680EA75C1E0023CCD6 /* ActiveDOMObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ActiveDOMObject.h; sourceTree = "<group>"; };
 		E1C4DE6D0EA75C650023CCD6 /* ActiveDOMObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ActiveDOMObject.cpp; sourceTree = "<group>"; };
+		E1C657261816F9FE00256CDD /* CryptoAlgorithmParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmParameters.h; sourceTree = "<group>"; };
 		E1C657241816E69D00256CDD /* CryptoAlgorithmIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmIdentifier.h; sourceTree = "<group>"; };
 		E1C6CFC21746D293007B87A1 /* DOMWindowConstructors.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = DOMWindowConstructors.idl; sourceTree = "<group>"; };
 		E1C8BE5C0E8BD15A0064CB7D /* JSWorker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWorker.cpp; sourceTree = "<group>"; };
@@ -12649,6 +12659,8 @@
 		E1FF8F62180745D800132674 /* JSSubtleCrypto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSSubtleCrypto.cpp; sourceTree = "<group>"; };
 		E1FF8F63180745D800132674 /* JSSubtleCrypto.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSSubtleCrypto.h; sourceTree = "<group>"; };
 		E1FF8F661807460800132674 /* JSSubtleCryptoCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSSubtleCryptoCustom.cpp; sourceTree = "<group>"; };
+		E1FF8F6A180DB5BE00132674 /* CryptoAlgorithmRegistry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoAlgorithmRegistry.cpp; sourceTree = "<group>"; };
+		E1FF8F6B180DB5BE00132674 /* CryptoAlgorithmRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmRegistry.h; sourceTree = "<group>"; };
 		E401C27417CE53EC00C41A35 /* ElementIteratorAssertions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ElementIteratorAssertions.h; sourceTree = "<group>"; };
 		E406F3FB1198307D009D59D6 /* ColorData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ColorData.cpp; sourceTree = "<group>"; };
 		E41EA038119836DB00710BC5 /* CSSPropertyNames.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSPropertyNames.cpp; sourceTree = "<group>"; };
@@ -20106,6 +20118,14 @@
 			name = objc;
 			sourceTree = "<group>";
 		};
+		E172AF71180F343400FBADB9 /* mac */ = {
+			isa = PBXGroup;
+			children = (
+				E172AF72180F352500FBADB9 /* CryptoAlgorithmRegistryMac.cpp */,
+			);
+			name = mac;
+			sourceTree = "<group>";
+		};
 		E1C8BE4B0E8BD0D10064CB7D /* Threads */ = {
 			isa = PBXGroup;
 			children = (
@@ -20218,9 +20238,15 @@
 		E1FF8F5B1807362B00132674 /* crypto */ = {
 			isa = PBXGroup;
 			children = (
+				E172AF71180F343400FBADB9 /* mac */,
+				E172AF6B180F24C600FBADB9 /* CryptoAlgorithm.cpp */,
+				E172AF6C180F24C600FBADB9 /* CryptoAlgorithm.h */,
 				E157A8EA181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.cpp */,
 				E157A8EB181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.h */,
 				E1C657241816E69D00256CDD /* CryptoAlgorithmIdentifier.h */,
+				E1C657261816F9FE00256CDD /* CryptoAlgorithmParameters.h */,
+				E1FF8F6A180DB5BE00132674 /* CryptoAlgorithmRegistry.cpp */,
+				E1FF8F6B180DB5BE00132674 /* CryptoAlgorithmRegistry.h */,
 				E157A8DC18172C2C009F821D /* CryptoKey.idl */,
 				E157A8E218173A3A009F821D /* CryptoKey.cpp */,
 				E157A8E318173A3A009F821D /* CryptoKey.h */,
@@ -21666,6 +21692,7 @@
 				FD5686CC13AC181400B69C68 /* AudioBufferCallback.h in Headers */,
 				FD315FFC12B0267600C1A359 /* AudioBufferSourceNode.h in Headers */,
 				FD31607C12B026F700C1A359 /* AudioBus.h in Headers */,
+				E1FF8F6D180DB5BE00132674 /* CryptoAlgorithmRegistry.h in Headers */,
 				07C59B5E17F4B208000FBCBB /* JSAudioStreamTrack.h in Headers */,
 				FD31607E12B026F700C1A359 /* AudioChannel.h in Headers */,
 				FD31600512B0267600C1A359 /* AudioContext.h in Headers */,
@@ -22682,6 +22709,7 @@
 				07277E5317D018CC0015534D /* JSMediaStreamTrack.h in Headers */,
 				D359D78A129CA2710006E5D2 /* HTMLDetailsElement.h in Headers */,
 				A8EA79FA0A1916DF00A8EF5F /* HTMLDirectoryElement.h in Headers */,
+				E1C657271816F9FE00256CDD /* CryptoAlgorithmParameters.h in Headers */,
 				A8EA7CB70A192B9C00A8EF5F /* HTMLDivElement.h in Headers */,
 				A8EA79F70A1916DF00A8EF5F /* HTMLDListElement.h in Headers */,
 				93F198E508245E59001E9ABC /* HTMLDocument.h in Headers */,
@@ -23066,6 +23094,7 @@
 				1AE2AA270A1CDAB400B42B25 /* JSHTMLFieldSetElement.h in Headers */,
 				1AE2AA290A1CDAB400B42B25 /* JSHTMLFontElement.h in Headers */,
 				9BF9A8811648DD2F001C6B23 /* JSHTMLFormControlsCollection.h in Headers */,
+				E172AF6E180F24C600FBADB9 /* CryptoAlgorithm.h in Headers */,
 				A8D064FC0A23C0CC005E7203 /* JSHTMLFormElement.h in Headers */,
 				BC4918C70BFEA050009D6316 /* JSHTMLFrameElement.h in Headers */,
 				BC926F810C0552470082776B /* JSHTMLFrameSetElement.h in Headers */,
@@ -26107,6 +26136,7 @@
 				1C81BA090E97348300266E07 /* _javascript_CallFrame.cpp in Sources */,
 				418F88040FF957AE0080F045 /* JSAbstractWorker.cpp in Sources */,
 				073BE34F17D18183002BD431 /* RTCIceCandidateDescriptor.cpp in Sources */,
+				E172AF6D180F24C600FBADB9 /* CryptoAlgorithm.cpp in Sources */,
 				FDA15EC912B03F50003A583A /* JSAnalyserNode.cpp in Sources */,
 				65DF31DA09D1C123000BE325 /* JSAttr.cpp in Sources */,
 				BC2ED6BC0C6BD2F000920BFF /* JSAttrCustom.cpp in Sources */,
@@ -27215,6 +27245,7 @@
 				9391A99C1629D70000297330 /* ScrollingTreeScrollingNode.cpp in Sources */,
 				93C4A4161629DF5A00C3EB6E /* ScrollingTreeScrollingNodeMac.mm in Sources */,
 				0FB8890B167D2FA10010CDA5 /* ScrollingTreeStickyNode.mm in Sources */,
+				E172AF74180F352500FBADB9 /* CryptoAlgorithmRegistryMac.cpp in Sources */,
 				BC2441C40E8B65D00055320F /* ScrollView.cpp in Sources */,
 				9353676B09AED88B00D35CD6 /* ScrollViewMac.mm in Sources */,
 				F55B3DD11251F12D003EF269 /* SearchInputType.cpp in Sources */,
@@ -27581,6 +27612,7 @@
 				B2AFFC990D00A5DF0030074D /* TextCodecMac.cpp in Sources */,
 				B2C3DA3F0D006C1D00EF6F26 /* TextCodecUserDefined.cpp in Sources */,
 				B2C3DA410D006C1D00EF6F26 /* TextCodecUTF16.cpp in Sources */,
+				E1FF8F6C180DB5BE00132674 /* CryptoAlgorithmRegistry.cpp in Sources */,
 				9343CB8112F25E510033C5EE /* TextCodecUTF8.cpp in Sources */,
 				142B97C913138943008BEF4B /* TextControlInnerElements.cpp in Sources */,
 				97BC84B312371180000C6161 /* TextDocument.cpp in Sources */,

Added: trunk/Source/WebCore/crypto/CryptoAlgorithm.cpp (0 => 158363)


--- trunk/Source/WebCore/crypto/CryptoAlgorithm.cpp	                        (rev 0)
+++ trunk/Source/WebCore/crypto/CryptoAlgorithm.cpp	2013-10-31 17:13:49 UTC (rev 158363)
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "CryptoAlgorithm.h"
+
+#if ENABLE(SUBTLE_CRYPTO)
+
+#include "ExceptionCode.h"
+
+namespace WebCore {
+
+CryptoAlgorithm::CryptoAlgorithm()
+{
+}
+
+CryptoAlgorithm::~CryptoAlgorithm()
+{
+}
+
+void CryptoAlgorithm::encrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
+{
+    ec = NOT_SUPPORTED_ERR;
+}
+
+void CryptoAlgorithm::decrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
+{
+    ec = NOT_SUPPORTED_ERR;
+}
+
+void CryptoAlgorithm::sign(const CryptoAlgorithmParameters&, const CryptoKey&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
+{
+    ec = NOT_SUPPORTED_ERR;
+}
+
+void CryptoAlgorithm::verify(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
+{
+    ec = NOT_SUPPORTED_ERR;
+}
+
+void CryptoAlgorithm::digest(const CryptoAlgorithmParameters&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
+{
+    ec = NOT_SUPPORTED_ERR;
+}
+
+void CryptoAlgorithm::generateKey(const CryptoAlgorithmParameters&, bool, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
+{
+    ec = NOT_SUPPORTED_ERR;
+}
+
+void CryptoAlgorithm::deriveKey(const CryptoAlgorithmParameters&, const CryptoKey&, CryptoAlgorithm*, bool, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
+{
+    ec = NOT_SUPPORTED_ERR;
+}
+
+void CryptoAlgorithm::deriveBits(const CryptoAlgorithmParameters&, const CryptoKey&, unsigned long, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
+{
+    ec = NOT_SUPPORTED_ERR;
+}
+
+void CryptoAlgorithm::importKey(const CryptoAlgorithmParameters&, CryptoKeyFormat, const CryptoOperationData&, bool, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
+{
+    ec = NOT_SUPPORTED_ERR;
+}
+
+void CryptoAlgorithm::exportKey(const CryptoAlgorithmParameters&, CryptoKeyFormat, const CryptoKey&, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
+{
+    ec = NOT_SUPPORTED_ERR;
+}
+
+void CryptoAlgorithm::wrapKey(const CryptoAlgorithmParameters&, CryptoKeyFormat, const CryptoKey&, const CryptoKey&, CryptoAlgorithm*, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
+{
+    ec = NOT_SUPPORTED_ERR;
+}
+
+void CryptoAlgorithm::unwrapKey(const CryptoAlgorithmParameters&, CryptoKeyFormat, const CryptoOperationData&, const CryptoKey&, CryptoAlgorithm*, CryptoAlgorithm*, bool, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
+{
+    ec = NOT_SUPPORTED_ERR;
+}
+
+}
+
+#endif

Added: trunk/Source/WebCore/crypto/CryptoAlgorithm.h (0 => 158363)


--- trunk/Source/WebCore/crypto/CryptoAlgorithm.h	                        (rev 0)
+++ trunk/Source/WebCore/crypto/CryptoAlgorithm.h	2013-10-31 17:13:49 UTC (rev 158363)
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CryptoAlgorithm_h
+#define CryptoAlgorithm_h
+
+#include "CryptoAlgorithmIdentifier.h"
+#include "CryptoKeyFormat.h"
+#include "CryptoKeyUsage.h"
+#include <wtf/Vector.h>
+
+#if ENABLE(SUBTLE_CRYPTO)
+
+namespace WebCore {
+
+typedef int ExceptionCode;
+
+class CryptoAlgorithmParameters;
+class CryptoKey;
+class PromiseWrapper;
+
+// Data is mutable, so async operations should copy it first.
+typedef std::pair<const char*, size_t> CryptoOperationData;
+
+class CryptoAlgorithm {
+    WTF_MAKE_NONCOPYABLE(CryptoAlgorithm)
+public:
+    virtual ~CryptoAlgorithm();
+
+    virtual CryptoAlgorithmIdentifier identifier() const = 0;
+
+    virtual void encrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
+    virtual void decrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
+    virtual void sign(const CryptoAlgorithmParameters&, const CryptoKey&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
+    virtual void verify(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData& signature, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
+    virtual void digest(const CryptoAlgorithmParameters&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
+    virtual void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
+    virtual void deriveKey(const CryptoAlgorithmParameters&, const CryptoKey& baseKey, CryptoAlgorithm* derivedKeyType, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
+    virtual void deriveBits(const CryptoAlgorithmParameters&, const CryptoKey& baseKey, unsigned long length, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
+    virtual void importKey(const CryptoAlgorithmParameters&, CryptoKeyFormat, const CryptoOperationData&, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
+    virtual void exportKey(const CryptoAlgorithmParameters&, CryptoKeyFormat, const CryptoKey&, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
+    virtual void wrapKey(const CryptoAlgorithmParameters&, CryptoKeyFormat, const CryptoKey&, const CryptoKey& wrappingKey, CryptoAlgorithm* wrapAlgorithm, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
+    virtual void unwrapKey(const CryptoAlgorithmParameters&, CryptoKeyFormat, const CryptoOperationData&, const CryptoKey& unwrappingKey, CryptoAlgorithm* unwrapAlgorithm, CryptoAlgorithm* unwrappedKeyAlgorithm, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
+
+protected:
+    CryptoAlgorithm();
+};
+
+}
+
+#endif // ENABLE(SUBTLE_CRYPTO)
+#endif // CryptoAlgorithm_h

Added: trunk/Source/WebCore/crypto/CryptoAlgorithmParameters.h (0 => 158363)


--- trunk/Source/WebCore/crypto/CryptoAlgorithmParameters.h	                        (rev 0)
+++ trunk/Source/WebCore/crypto/CryptoAlgorithmParameters.h	2013-10-31 17:13:49 UTC (rev 158363)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CryptoAlgorithmParameters_h
+#define CryptoAlgorithmParameters_h
+
+#include <wtf/Noncopyable.h>
+
+#if ENABLE(SUBTLE_CRYPTO)
+
+namespace WebCore {
+
+class CryptoAlgorithmParameters {
+    WTF_MAKE_NONCOPYABLE(CryptoAlgorithmParameters);
+public:
+    CryptoAlgorithmParameters() { }
+    virtual ~CryptoAlgorithmParameters() { }
+};
+
+}
+
+#endif // ENABLE(SUBTLE_CRYPTO)
+#endif // CryptoAlgorithmParameters_h

Added: trunk/Source/WebCore/crypto/CryptoAlgorithmRegistry.cpp (0 => 158363)


--- trunk/Source/WebCore/crypto/CryptoAlgorithmRegistry.cpp	                        (rev 0)
+++ trunk/Source/WebCore/crypto/CryptoAlgorithmRegistry.cpp	2013-10-31 17:13:49 UTC (rev 158363)
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "CryptoAlgorithmRegistry.h"
+
+#if ENABLE(SUBTLE_CRYPTO)
+
+#include "CryptoAlgorithm.h"
+#include <wtf/MainThread.h>
+
+namespace WebCore {
+
+CryptoAlgorithmRegistry& CryptoAlgorithmRegistry::shared()
+{
+    ASSERT(isMainThread());
+    DEFINE_STATIC_LOCAL(CryptoAlgorithmRegistry, registry, ());
+    return registry;
+}
+
+CryptoAlgorithmRegistry::CryptoAlgorithmRegistry()
+{
+    platformRegisterAlgorithms();
+}
+
+bool CryptoAlgorithmRegistry::getIdentifierForName(const String& name, CryptoAlgorithmIdentifier& result)
+{
+    auto iter = m_nameToIdentifierMap.find(name.lower());
+    if (iter == m_nameToIdentifierMap.end())
+        return false;
+
+    result = iter->value;
+    return true;
+}
+
+String CryptoAlgorithmRegistry::nameForIdentifier(CryptoAlgorithmIdentifier identifier)
+{
+    return m_identifierToNameMap.get(static_cast<unsigned>(identifier));
+}
+
+std::unique_ptr<CryptoAlgorithm> CryptoAlgorithmRegistry::create(CryptoAlgorithmIdentifier identifier)
+{
+    auto iter = m_identifierToConstructorMap.find(static_cast<unsigned>(identifier));
+    if (iter == m_identifierToConstructorMap.end())
+        return nullptr;
+
+    return iter->value();
+}
+
+void CryptoAlgorithmRegistry::registerAlgorithm(const String& name, CryptoAlgorithmIdentifier identifier, CryptoAlgorithmConstructor constructor)
+{
+    ASSERT(name == name.lower());
+
+    bool added = m_nameToIdentifierMap.add(name, identifier).isNewEntry;
+    ASSERT_UNUSED(added, added);
+
+    added = m_identifierToNameMap.add(static_cast<unsigned>(identifier), name).isNewEntry;
+    ASSERT_UNUSED(added, added);
+
+    added = m_identifierToConstructorMap.add(static_cast<unsigned>(identifier), constructor).isNewEntry;
+    ASSERT_UNUSED(added, added);
+}
+
+
+} // namespace WebCore
+
+#endif // ENABLE(SUBTLE_CRYPTO)

Added: trunk/Source/WebCore/crypto/CryptoAlgorithmRegistry.h (0 => 158363)


--- trunk/Source/WebCore/crypto/CryptoAlgorithmRegistry.h	                        (rev 0)
+++ trunk/Source/WebCore/crypto/CryptoAlgorithmRegistry.h	2013-10-31 17:13:49 UTC (rev 158363)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CryptoAlgorithmRegistry_h
+#define CryptoAlgorithmRegistry_h
+
+#include <wtf/Forward.h>
+#include <wtf/HashMap.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/text/StringHash.h>
+#include "CryptoAlgorithmIdentifier.h"
+
+#if ENABLE(SUBTLE_CRYPTO)
+
+namespace WebCore {
+
+typedef int ExceptionCode;
+
+class CryptoAlgorithm;
+
+class CryptoAlgorithmRegistry {
+    WTF_MAKE_NONCOPYABLE(CryptoAlgorithmRegistry);
+
+public:
+    static CryptoAlgorithmRegistry& shared();
+
+    bool getIdentifierForName(const String&, CryptoAlgorithmIdentifier&);
+    String nameForIdentifier(CryptoAlgorithmIdentifier);
+
+    std::unique_ptr<CryptoAlgorithm> create(CryptoAlgorithmIdentifier);
+
+private:
+    CryptoAlgorithmRegistry();
+    void platformRegisterAlgorithms();
+
+    typedef std::unique_ptr<CryptoAlgorithm> (*CryptoAlgorithmConstructor)();
+
+    void registerAlgorithm(const String& name, CryptoAlgorithmIdentifier, CryptoAlgorithmConstructor);
+    HashMap<String, CryptoAlgorithmIdentifier> m_nameToIdentifierMap;
+    HashMap<unsigned, String> m_identifierToNameMap;
+    HashMap<unsigned, CryptoAlgorithmConstructor> m_identifierToConstructorMap;
+};
+
+}
+
+#endif // ENABLE(SUBTLE_CRYPTO)
+#endif // CryptoAlgorithmRegistry_h

Added: trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRegistryMac.cpp (0 => 158363)


--- trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRegistryMac.cpp	                        (rev 0)
+++ trunk/Source/WebCore/crypto/mac/CryptoAlgorithmRegistryMac.cpp	2013-10-31 17:13:49 UTC (rev 158363)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "CryptoAlgorithmRegistry.h"
+
+#if ENABLE(SUBTLE_CRYPTO)
+
+//#include "CryptoAlgorithmHMAC.h"
+//#include "CryptoAlgorithmSHA1.h"
+
+namespace WebCore {
+
+void CryptoAlgorithmRegistry::platformRegisterAlgorithms()
+{
+//    registerAlgorithm(CryptoAlgorithmHMAC::m_name, CryptoAlgorithmHMAC::m_identifier, CryptoAlgorithmHMAC::create);
+//    registerAlgorithm(CryptoAlgorithmSHA1::m_name, CryptoAlgorithmSHA1::m_identifier, CryptoAlgorithmSHA1::create);
+}
+
+}
+
+#endif // ENABLE(SUBTLE_CRYPTO)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to