| OLD | NEW | 
| (Empty) |  | 
 |    1 /* | 
 |    2  * Copyright (C) 2014 Google Inc. All rights reserved. | 
 |    3  * | 
 |    4  * Redistribution and use in source and binary forms, with or without | 
 |    5  * modification, are permitted provided that the following conditions are | 
 |    6  * met: | 
 |    7  * | 
 |    8  *     * Redistributions of source code must retain the above copyright | 
 |    9  * notice, this list of conditions and the following disclaimer. | 
 |   10  *     * Redistributions in binary form must reproduce the above | 
 |   11  * copyright notice, this list of conditions and the following disclaimer | 
 |   12  * in the documentation and/or other materials provided with the | 
 |   13  * distribution. | 
 |   14  *     * Neither the name of Google Inc. nor the names of its | 
 |   15  * contributors may be used to endorse or promote products derived from | 
 |   16  * this software without specific prior written permission. | 
 |   17  * | 
 |   18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
 |   19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
 |   20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 
 |   21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 
 |   22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 
 |   23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 
 |   24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
 |   25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
 |   26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
 |   27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
 |   28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
 |   29  */ | 
 |   30  | 
 |   31 #ifndef WebCryptoKeyAlgorithmParams_h | 
 |   32 #define WebCryptoKeyAlgorithmParams_h | 
 |   33  | 
 |   34 #include "WebCommon.h" | 
 |   35 #include "WebCryptoAlgorithm.h" | 
 |   36 #include "WebVector.h" | 
 |   37  | 
 |   38 namespace blink { | 
 |   39  | 
 |   40 enum WebCryptoKeyAlgorithmParamsType { | 
 |   41     WebCryptoKeyAlgorithmParamsTypeNone, | 
 |   42     WebCryptoKeyAlgorithmParamsTypeHmac, | 
 |   43     WebCryptoKeyAlgorithmParamsTypeAes, | 
 |   44     WebCryptoKeyAlgorithmParamsTypeRsa, | 
 |   45     WebCryptoKeyAlgorithmParamsTypeRsaHashed | 
 |   46 }; | 
 |   47  | 
 |   48 class WebCryptoKeyAlgorithmParams { | 
 |   49 public: | 
 |   50     virtual ~WebCryptoKeyAlgorithmParams() { } | 
 |   51     virtual WebCryptoKeyAlgorithmParamsType type() const | 
 |   52     { | 
 |   53         return WebCryptoKeyAlgorithmParamsTypeNone; | 
 |   54     } | 
 |   55 }; | 
 |   56  | 
 |   57 class WebCryptoAesKeyAlgorithmParams : public WebCryptoKeyAlgorithmParams { | 
 |   58 public: | 
 |   59     explicit WebCryptoAesKeyAlgorithmParams(unsigned short lengthBits) | 
 |   60         : m_lengthBits(lengthBits) | 
 |   61     { | 
 |   62     } | 
 |   63  | 
 |   64     unsigned short lengthBits() const | 
 |   65     { | 
 |   66         return m_lengthBits; | 
 |   67     } | 
 |   68  | 
 |   69     virtual WebCryptoKeyAlgorithmParamsType type() const | 
 |   70     { | 
 |   71         return WebCryptoKeyAlgorithmParamsTypeAes; | 
 |   72     } | 
 |   73  | 
 |   74 private: | 
 |   75     unsigned short m_lengthBits; | 
 |   76 }; | 
 |   77  | 
 |   78 class WebCryptoHmacKeyAlgorithmParams : public WebCryptoKeyAlgorithmParams { | 
 |   79 public: | 
 |   80     explicit WebCryptoHmacKeyAlgorithmParams(const WebCryptoAlgorithm& hash) | 
 |   81         : m_hash(hash) | 
 |   82     { | 
 |   83     } | 
 |   84  | 
 |   85     const WebCryptoAlgorithm& hash() const | 
 |   86     { | 
 |   87         return m_hash; | 
 |   88     } | 
 |   89  | 
 |   90     virtual WebCryptoKeyAlgorithmParamsType type() const | 
 |   91     { | 
 |   92         return WebCryptoKeyAlgorithmParamsTypeHmac; | 
 |   93     } | 
 |   94  | 
 |   95 private: | 
 |   96     WebCryptoAlgorithm m_hash; | 
 |   97 }; | 
 |   98  | 
 |   99 class WebCryptoRsaKeyAlgorithmParams : public WebCryptoKeyAlgorithmParams { | 
 |  100 public: | 
 |  101     WebCryptoRsaKeyAlgorithmParams(unsigned modulusLengthBits, const unsigned ch
     ar* publicExponent, unsigned publicExponentSize) | 
 |  102         : m_modulusLengthBits(modulusLengthBits) | 
 |  103         , m_publicExponent(publicExponent, publicExponentSize) | 
 |  104     { | 
 |  105     } | 
 |  106  | 
 |  107     unsigned modulusLengthBits() const | 
 |  108     { | 
 |  109         return m_modulusLengthBits; | 
 |  110     } | 
 |  111  | 
 |  112     const WebVector<unsigned char>& publicExponent() const | 
 |  113     { | 
 |  114         return m_publicExponent; | 
 |  115     } | 
 |  116  | 
 |  117     virtual WebCryptoKeyAlgorithmParamsType type() const | 
 |  118     { | 
 |  119         return WebCryptoKeyAlgorithmParamsTypeRsa; | 
 |  120     } | 
 |  121  | 
 |  122 private: | 
 |  123     unsigned m_modulusLengthBits; | 
 |  124     WebVector<unsigned char> m_publicExponent; | 
 |  125 }; | 
 |  126  | 
 |  127 class WebCryptoRsaHashedKeyAlgorithmParams : public WebCryptoRsaKeyAlgorithmPara
     ms { | 
 |  128 public: | 
 |  129     WebCryptoRsaHashedKeyAlgorithmParams(unsigned modulusLengthBits, const unsig
     ned char* publicExponent, unsigned publicExponentSize, const WebCryptoAlgorithm&
      hash) | 
 |  130         : WebCryptoRsaKeyAlgorithmParams(modulusLengthBits, publicExponent, publ
     icExponentSize) | 
 |  131         , m_hash(hash) | 
 |  132     { | 
 |  133     } | 
 |  134  | 
 |  135     const WebCryptoAlgorithm& hash() const | 
 |  136     { | 
 |  137         return m_hash; | 
 |  138     } | 
 |  139  | 
 |  140     virtual WebCryptoKeyAlgorithmParamsType type() const | 
 |  141     { | 
 |  142         return WebCryptoKeyAlgorithmParamsTypeRsaHashed; | 
 |  143     } | 
 |  144  | 
 |  145 private: | 
 |  146     WebCryptoAlgorithm m_hash; | 
 |  147 }; | 
 |  148  | 
 |  149 } // namespace blink | 
 |  150  | 
 |  151 #endif | 
| OLD | NEW |