mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 10:42:45 +00:00 
			
		
		
		
	 649d2faeab
			
		
	
	
		649d2faeab
		
	
	
	
	
		
			
			We had some inconsistencies before: - Sometimes "The", sometimes "the" - Sometimes trailing ".", sometimes no trailing "." I picked the most common one (lowecase "the", trailing ".") and applied it to all copyright headers. By using the exact same string everywhere we can ensure nothing gets missed during a global search (and replace), and that these inconsistencies are not spread any further (as copyright headers are commonly copied to new files).
		
			
				
	
	
		
			65 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2020, the SerenityOS developers.
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <AK/Span.h>
 | |
| #include <AK/Types.h>
 | |
| #include <LibCrypto/Checksum/ChecksumFunction.h>
 | |
| 
 | |
| namespace Crypto::Checksum {
 | |
| 
 | |
| struct Table {
 | |
|     u32 data[256];
 | |
| 
 | |
|     constexpr Table()
 | |
|         : data()
 | |
|     {
 | |
|         for (auto i = 0; i < 256; i++) {
 | |
|             u32 value = i;
 | |
| 
 | |
|             for (auto j = 0; j < 8; j++) {
 | |
|                 if (value & 1) {
 | |
|                     value = 0xEDB88320 ^ (value >> 1);
 | |
|                 } else {
 | |
|                     value = value >> 1;
 | |
|                 }
 | |
|             }
 | |
| 
 | |
|             data[i] = value;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     constexpr u32 operator[](int index) const
 | |
|     {
 | |
|         return data[index];
 | |
|     }
 | |
| };
 | |
| 
 | |
| constexpr static auto table = Table();
 | |
| 
 | |
| class CRC32 : public ChecksumFunction<u32> {
 | |
| public:
 | |
|     CRC32() { }
 | |
|     CRC32(ReadonlyBytes data)
 | |
|     {
 | |
|         update(data);
 | |
|     }
 | |
| 
 | |
|     CRC32(u32 initial_state, ReadonlyBytes data)
 | |
|         : m_state(initial_state)
 | |
|     {
 | |
|         update(data);
 | |
|     }
 | |
| 
 | |
|     void update(ReadonlyBytes data);
 | |
|     u32 digest();
 | |
| 
 | |
| private:
 | |
|     u32 m_state { ~0u };
 | |
| };
 | |
| 
 | |
| }
 |