| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 // of forcing length() to be the size of the buffer used to create the | 52 // of forcing length() to be the size of the buffer used to create the |
| 53 // string, prior to inserting the null terminator earlier in the | 53 // string, prior to inserting the null terminator earlier in the |
| 54 // sequence. | 54 // sequence. |
| 55 ASSERT(input.length() == strlen(string)); | 55 ASSERT(input.length() == strlen(string)); |
| 56 addBytes(reinterpret_cast<const uint8_t*>(string), input.length()); | 56 addBytes(reinterpret_cast<const uint8_t*>(string), input.length()); |
| 57 } | 57 } |
| 58 void addBytes(const uint8_t* input, size_t length); | 58 void addBytes(const uint8_t* input, size_t length); |
| 59 | 59 |
| 60 // computeHash has a side effect of resetting the state of the object. | 60 // computeHash has a side effect of resetting the state of the object. |
| 61 void computeHash(Vector<uint8_t, 20>&); | 61 void computeHash(Vector<uint8_t, 20>&); |
| 62 | 62 |
| 63 // Get a hex hash from the digest. Pass a limit less than 40 if you want a s
horter digest. | 63 // Get a hex hash from the digest. Pass a limit less than 40 if you want a s
horter digest. |
| 64 static CString hexDigest(const Vector<uint8_t, 20>&); | 64 static CString hexDigest(const Vector<uint8_t, 20>&); |
| 65 | 65 |
| 66 // Compute the hex digest directly. Pass a limit less than 40 if you want a
shorter digest. | 66 // Compute the hex digest directly. Pass a limit less than 40 if you want a
shorter digest. |
| 67 CString computeHexDigest(); | 67 CString computeHexDigest(); |
| 68 | 68 |
| 69 private: | 69 private: |
| 70 void finalize(); | 70 void finalize(); |
| 71 void processBlock(); | 71 void processBlock(); |
| 72 void reset(); | 72 void reset(); |
| 73 | 73 |
| 74 uint8_t m_buffer[64]; | 74 uint8_t m_buffer[64]; |
| 75 size_t m_cursor; // Number of bytes filled in m_buffer (0-64). | 75 size_t m_cursor; // Number of bytes filled in m_buffer (0-64). |
| 76 uint64_t m_totalBytes; // Number of bytes added so far. | 76 uint64_t m_totalBytes; // Number of bytes added so far. |
| 77 uint32_t m_hash[5]; | 77 uint32_t m_hash[5]; |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 } // namespace WTF | 80 } // namespace WTF |
| 81 | 81 |
| 82 using WTF::SHA1; | 82 using WTF::SHA1; |
| 83 | 83 |
| 84 #endif // WTF_SHA1_h | 84 #endif // WTF_SHA1_h |
| OLD | NEW |