Initialize a sha1_git_hasher with an optional ``msg`` byte string. The ``total_length`` of all content that will be hashed, combining the ``msg`` length plus any later call to update() with additional messages. Here ``total_length`` is total length in bytes of all t
(self, msg=None, total_length=0, **kwargs)
| 134 | """ |
| 135 | |
| 136 | def __init__(self, msg=None, total_length=0, **kwargs): |
| 137 | """ |
| 138 | Initialize a sha1_git_hasher with an optional ``msg`` byte string. The ``total_length`` of |
| 139 | all content that will be hashed, combining the ``msg`` length plus any later call to |
| 140 | update() with additional messages. |
| 141 | |
| 142 | Here ``total_length`` is total length in bytes of all the messages (chunks) hashed |
| 143 | in contrast to ``msg_len`` which is the length in bytes for the optional message. |
| 144 | """ |
| 145 | self.digest_size = 160 // 8 |
| 146 | self.msg_len = 0 |
| 147 | |
| 148 | if msg: |
| 149 | self.msg_len = msg_len = len(msg) |
| 150 | |
| 151 | if not total_length: |
| 152 | total_length = msg_len |
| 153 | else: |
| 154 | if total_length < msg_len: |
| 155 | raise ValueError( |
| 156 | f"Initial msg length: {msg_len} " |
| 157 | f"cannot be larger than the the total_length: {self.total_length}" |
| 158 | ) |
| 159 | |
| 160 | if not total_length: |
| 161 | raise ValueError("total_length cannot be zero") |
| 162 | |
| 163 | self.total_length = total_length |
| 164 | self.binh = get_hasher(bitsize=160)(total_length=total_length) |
| 165 | |
| 166 | self._hash_header() |
| 167 | if msg: |
| 168 | self.update(msg) |
| 169 | |
| 170 | def _hash_header(self): |
| 171 | # note: bytes interpolation is new in Python 3.5 |
nothing calls this directly
no test coverage detected