OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 #ifndef WebCryptoKeyAlgorithmParams_h | 31 #ifndef WebCryptoKeyAlgorithmParams_h |
32 #define WebCryptoKeyAlgorithmParams_h | 32 #define WebCryptoKeyAlgorithmParams_h |
33 | 33 |
34 #include "WebCommon.h" | 34 #include "WebCommon.h" |
35 #include "WebCryptoAlgorithm.h" | 35 #include "WebCryptoAlgorithm.h" |
36 #include "WebVector.h" | 36 #include "WebVector.h" |
37 | 37 |
38 namespace blink { | 38 namespace blink { |
39 | 39 |
| 40 // Interface used for serializing WebCryptoKeyAlgorithmParams to a javascript |
| 41 // dictionary. |
| 42 class WebCryptoKeyAlgorithmDictionary { |
| 43 public: |
| 44 virtual ~WebCryptoKeyAlgorithmDictionary() { } |
| 45 |
| 46 virtual void setString(const char*, const char*) = 0; |
| 47 virtual void setUint(const char*, unsigned) = 0; |
| 48 virtual void setAlgorithm(const char*, const WebCryptoAlgorithm&) = 0; |
| 49 virtual void setUint8Array(const char*, const WebVector<unsigned char>&) = 0
; |
| 50 }; |
| 51 |
40 enum WebCryptoKeyAlgorithmParamsType { | 52 enum WebCryptoKeyAlgorithmParamsType { |
41 WebCryptoKeyAlgorithmParamsTypeNone, | 53 WebCryptoKeyAlgorithmParamsTypeNone, |
42 WebCryptoKeyAlgorithmParamsTypeHmac, | 54 WebCryptoKeyAlgorithmParamsTypeHmac, |
43 WebCryptoKeyAlgorithmParamsTypeAes, | 55 WebCryptoKeyAlgorithmParamsTypeAes, |
44 WebCryptoKeyAlgorithmParamsTypeRsaHashed | 56 WebCryptoKeyAlgorithmParamsTypeRsaHashed |
45 }; | 57 }; |
46 | 58 |
47 class WebCryptoKeyAlgorithmParams { | 59 class WebCryptoKeyAlgorithmParams { |
48 public: | 60 public: |
49 virtual ~WebCryptoKeyAlgorithmParams() { } | 61 virtual ~WebCryptoKeyAlgorithmParams() { } |
50 virtual WebCryptoKeyAlgorithmParamsType type() const | 62 virtual WebCryptoKeyAlgorithmParamsType type() const |
51 { | 63 { |
52 return WebCryptoKeyAlgorithmParamsTypeNone; | 64 return WebCryptoKeyAlgorithmParamsTypeNone; |
53 } | 65 } |
| 66 |
| 67 virtual void writeToDictionary(WebCryptoKeyAlgorithmDictionary*) const = 0; |
54 }; | 68 }; |
55 | 69 |
56 class WebCryptoAesKeyAlgorithmParams : public WebCryptoKeyAlgorithmParams { | 70 class WebCryptoAesKeyAlgorithmParams : public WebCryptoKeyAlgorithmParams { |
57 public: | 71 public: |
58 explicit WebCryptoAesKeyAlgorithmParams(unsigned short lengthBits) | 72 explicit WebCryptoAesKeyAlgorithmParams(unsigned short lengthBits) |
59 : m_lengthBits(lengthBits) | 73 : m_lengthBits(lengthBits) |
60 { | 74 { |
61 } | 75 } |
62 | 76 |
63 unsigned short lengthBits() const | 77 unsigned short lengthBits() const |
64 { | 78 { |
65 return m_lengthBits; | 79 return m_lengthBits; |
66 } | 80 } |
67 | 81 |
68 virtual WebCryptoKeyAlgorithmParamsType type() const | 82 virtual WebCryptoKeyAlgorithmParamsType type() const |
69 { | 83 { |
70 return WebCryptoKeyAlgorithmParamsTypeAes; | 84 return WebCryptoKeyAlgorithmParamsTypeAes; |
71 } | 85 } |
72 | 86 |
| 87 virtual void writeToDictionary(WebCryptoKeyAlgorithmDictionary* dict) const |
| 88 { |
| 89 dict->setUint("length", m_lengthBits); |
| 90 } |
| 91 |
73 private: | 92 private: |
74 unsigned short m_lengthBits; | 93 unsigned short m_lengthBits; |
75 }; | 94 }; |
76 | 95 |
77 class WebCryptoHmacKeyAlgorithmParams : public WebCryptoKeyAlgorithmParams { | 96 class WebCryptoHmacKeyAlgorithmParams : public WebCryptoKeyAlgorithmParams { |
78 public: | 97 public: |
79 WebCryptoHmacKeyAlgorithmParams(const WebCryptoAlgorithm& hash, unsigned len
gthBits) | 98 WebCryptoHmacKeyAlgorithmParams(const WebCryptoAlgorithm& hash, unsigned len
gthBits) |
80 : m_hash(hash) | 99 : m_hash(hash) |
81 , m_lengthBits(lengthBits) | 100 , m_lengthBits(lengthBits) |
82 { | 101 { |
83 } | 102 } |
84 | 103 |
85 const WebCryptoAlgorithm& hash() const | 104 const WebCryptoAlgorithm& hash() const |
86 { | 105 { |
87 return m_hash; | 106 return m_hash; |
88 } | 107 } |
89 | 108 |
90 unsigned lengthBits() const | 109 unsigned lengthBits() const |
91 { | 110 { |
92 return m_lengthBits; | 111 return m_lengthBits; |
93 } | 112 } |
94 | 113 |
95 virtual WebCryptoKeyAlgorithmParamsType type() const | 114 virtual WebCryptoKeyAlgorithmParamsType type() const |
96 { | 115 { |
97 return WebCryptoKeyAlgorithmParamsTypeHmac; | 116 return WebCryptoKeyAlgorithmParamsTypeHmac; |
98 } | 117 } |
99 | 118 |
| 119 virtual void writeToDictionary(WebCryptoKeyAlgorithmDictionary* dict) const |
| 120 { |
| 121 dict->setAlgorithm("hash", m_hash); |
| 122 dict->setUint("length", m_lengthBits); |
| 123 } |
| 124 |
100 private: | 125 private: |
101 WebCryptoAlgorithm m_hash; | 126 WebCryptoAlgorithm m_hash; |
102 unsigned m_lengthBits; | 127 unsigned m_lengthBits; |
103 }; | 128 }; |
104 | 129 |
105 class WebCryptoRsaHashedKeyAlgorithmParams : public WebCryptoKeyAlgorithmParams
{ | 130 class WebCryptoRsaHashedKeyAlgorithmParams : public WebCryptoKeyAlgorithmParams
{ |
106 public: | 131 public: |
107 WebCryptoRsaHashedKeyAlgorithmParams(unsigned modulusLengthBits, const unsig
ned char* publicExponent, unsigned publicExponentSize, const WebCryptoAlgorithm&
hash) | 132 WebCryptoRsaHashedKeyAlgorithmParams(unsigned modulusLengthBits, const unsig
ned char* publicExponent, unsigned publicExponentSize, const WebCryptoAlgorithm&
hash) |
108 : m_modulusLengthBits(modulusLengthBits) | 133 : m_modulusLengthBits(modulusLengthBits) |
109 , m_publicExponent(publicExponent, publicExponentSize) | 134 , m_publicExponent(publicExponent, publicExponentSize) |
(...skipping 14 matching lines...) Expand all Loading... |
124 const WebCryptoAlgorithm& hash() const | 149 const WebCryptoAlgorithm& hash() const |
125 { | 150 { |
126 return m_hash; | 151 return m_hash; |
127 } | 152 } |
128 | 153 |
129 virtual WebCryptoKeyAlgorithmParamsType type() const | 154 virtual WebCryptoKeyAlgorithmParamsType type() const |
130 { | 155 { |
131 return WebCryptoKeyAlgorithmParamsTypeRsaHashed; | 156 return WebCryptoKeyAlgorithmParamsTypeRsaHashed; |
132 } | 157 } |
133 | 158 |
| 159 virtual void writeToDictionary(WebCryptoKeyAlgorithmDictionary* dict) const |
| 160 { |
| 161 dict->setAlgorithm("hash", m_hash); |
| 162 dict->setUint("modulusLength", m_modulusLengthBits); |
| 163 dict->setUint8Array("publicExponent", m_publicExponent); |
| 164 } |
| 165 |
134 private: | 166 private: |
135 unsigned m_modulusLengthBits; | 167 unsigned m_modulusLengthBits; |
136 WebVector<unsigned char> m_publicExponent; | 168 WebVector<unsigned char> m_publicExponent; |
137 WebCryptoAlgorithm m_hash; | 169 WebCryptoAlgorithm m_hash; |
138 }; | 170 }; |
139 | 171 |
140 } // namespace blink | 172 } // namespace blink |
141 | 173 |
142 #endif | 174 #endif |
OLD | NEW |