7
7
use crate :: consts:: CRC_64_NVME ;
8
8
use crate :: CrcAlgorithm ;
9
9
use crate :: CrcParams ;
10
- use crc:: Table ;
10
+ use crc:: { Algorithm , Table } ;
11
11
12
12
const RUST_CRC32_AIXM : crc:: Crc < u32 , Table < 16 > > =
13
13
crc:: Crc :: < u32 , Table < 16 > > :: new ( & crc:: CRC_32_AIXM ) ;
@@ -78,6 +78,23 @@ pub(crate) fn update(state: u64, data: &[u8], params: CrcParams) -> u64 {
78
78
CrcAlgorithm :: Crc32Mef => RUST_CRC32_MEF ,
79
79
CrcAlgorithm :: Crc32Mpeg2 => RUST_CRC32_MPEG_2 ,
80
80
CrcAlgorithm :: Crc32Xfer => RUST_CRC32_XFER ,
81
+ CrcAlgorithm :: Crc32Custom => {
82
+ let algorithm: Algorithm < u32 > = Algorithm {
83
+ width : params. width as u8 ,
84
+ poly : params. poly as u32 ,
85
+ init : params. init as u32 ,
86
+ refin : params. refin ,
87
+ refout : params. refout ,
88
+ xorout : params. xorout as u32 ,
89
+ check : params. check as u32 ,
90
+ residue : 0x00000000 , // unused in this context
91
+ } ;
92
+
93
+ // ugly, but the crc crate is difficult to work with...
94
+ let static_algorithm = Box :: leak ( Box :: new ( algorithm) ) ;
95
+
96
+ crc:: Crc :: < u32 , Table < 16 > > :: new ( static_algorithm)
97
+ }
81
98
_ => panic ! ( "Invalid algorithm for u32 CRC" ) ,
82
99
} ;
83
100
update_u32 ( state as u32 , data, params) as u64
@@ -91,6 +108,23 @@ pub(crate) fn update(state: u64, data: &[u8], params: CrcParams) -> u64 {
91
108
CrcAlgorithm :: Crc64Redis => RUST_CRC64_REDIS ,
92
109
CrcAlgorithm :: Crc64We => RUST_CRC64_WE ,
93
110
CrcAlgorithm :: Crc64Xz => RUST_CRC64_XZ ,
111
+ CrcAlgorithm :: Crc64Custom => {
112
+ let algorithm: Algorithm < u64 > = Algorithm {
113
+ width : params. width as u8 ,
114
+ poly : params. poly as u64 ,
115
+ init : params. init as u64 ,
116
+ refin : params. refin ,
117
+ refout : params. refout ,
118
+ xorout : params. xorout as u64 ,
119
+ check : params. check as u64 ,
120
+ residue : 0x0000000000000000 , // unused in this context
121
+ } ;
122
+
123
+ // ugly, but the crc crate is difficult to work with...
124
+ let static_algorithm = Box :: leak ( Box :: new ( algorithm) ) ;
125
+
126
+ crc:: Crc :: < u64 , Table < 16 > > :: new ( static_algorithm)
127
+ }
94
128
_ => panic ! ( "Invalid algorithm for u64 CRC" ) ,
95
129
} ;
96
130
update_u64 ( state, data, params)
0 commit comments