Skip to content

Commit 7e01881

Browse files
heikkitoivonencodex
andcommitted
Docs: Fix stdlib hashing and http notes
Co-Authored-By: Codex <codex@openai.com>
1 parent 2a10d79 commit 7e01881

5 files changed

Lines changed: 41 additions & 32 deletions

File tree

docs/stdlib/hashlib.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,17 @@ import time
275275

276276
data = b"x" * (1024 * 1024) # 1MB
277277

278-
# MD5 (fastest, insecure)
278+
# MD5 (fast, insecure)
279279
start = time.time()
280280
hashlib.md5(data).digest() # O(1MB)
281281
md5_time = time.time() - start
282282

283-
# SHA256 (slower, secure)
283+
# SHA256 (secure)
284284
start = time.time()
285285
hashlib.sha256(data).digest() # O(1MB)
286286
sha256_time = time.time() - start
287287

288-
# SHA512 (slowest, more secure)
288+
# SHA512 (secure; speed varies by platform)
289289
start = time.time()
290290
hashlib.sha512(data).digest() # O(1MB)
291291
sha512_time = time.time() - start
@@ -321,7 +321,22 @@ assert digest1 == digest2
321321
import hashlib
322322

323323
# Algorithms guaranteed available
324-
guaranteed = {'md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512'}
324+
guaranteed = {
325+
'md5',
326+
'sha1',
327+
'sha224',
328+
'sha256',
329+
'sha384',
330+
'sha512',
331+
'blake2b',
332+
'blake2s',
333+
'sha3_224',
334+
'sha3_256',
335+
'sha3_384',
336+
'sha3_512',
337+
'shake_128',
338+
'shake_256',
339+
}
325340

326341
# Algorithms available on system
327342
available = set(hashlib.algorithms_available)

docs/stdlib/heapq.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ fifo_queue = deque() # Simple FIFO
201201
heapq.heappush(heap_queue, (priority, task)) # O(log n)
202202
fifo_queue.append(task) # O(1)
203203

204-
# Get task with priority
205-
task = heapq.heappop(heap_queue) # O(log n), gets highest priority
204+
# Get task with priority (smallest priority value first)
205+
task = heapq.heappop(heap_queue) # O(log n)
206206
task = fifo_queue.popleft() # O(1), gets oldest
207207
```
208208

docs/stdlib/hmac.md

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ The `hmac` module provides HMAC (Hash-based Message Authentication Code) functio
66

77
| Operation | Time | Space | Notes |
88
|-----------|------|-------|-------|
9-
| `hmac.new(key, msg, digestmod)` | O(n) | O(n) | Create HMAC, n = msg size |
10-
| `HMAC.update(msg)` | O(n) | O(k) | Add data to digest, k = hash block size |
9+
| `hmac.new(key, msg, digestmod)` | O(n) | O(1) | Create HMAC, n = msg size |
10+
| `HMAC.update(msg)` | O(n) | O(1) | Add data to digest, k = hash block size |
1111
| `HMAC.digest()` | O(k) | O(k) | Get binary digest, k = hash output size |
1212
| `HMAC.hexdigest()` | O(k) | O(k) | Get hex digest |
13-
| `hmac.compare_digest(a, b)` | O(n) | O(1) | Constant-time comparison |
13+
| `hmac.compare_digest(a, b)` | O(n) | O(1) | Timing-safe for equal-length inputs |
1414

1515
## Creating HMAC
1616

@@ -33,14 +33,14 @@ h = hmac.new(key, message, hashlib.sha256) # O(n)
3333
digest = h.digest() # O(k) where k = output size
3434
```
3535

36-
### Space Complexity: O(n)
36+
### Space Complexity: O(1)
3737

3838
```python
3939
import hmac
4040
import hashlib
4141

42-
# Memory for message processing
43-
h = hmac.new(key, message, hashlib.sha256) # O(n) for buffering
42+
# No buffering of the full message (beyond the input itself)
43+
h = hmac.new(key, message, hashlib.sha256) # O(1) extra space
4444
```
4545

4646
## Streaming Updates
@@ -127,22 +127,22 @@ import hashlib
127127

128128
message = b'data' * 1000
129129

130-
# MD5: Fast but deprecated
130+
# MD5: Deprecated (cryptographically broken)
131131
# O(n) time
132132
h = hmac.new(b'key', message, hashlib.md5) # O(n)
133133
digest = h.digest() # O(16) bytes
134134

135-
# SHA1: Faster than SHA256, deprecated
135+
# SHA1: Deprecated (cryptographically broken)
136136
# O(n) time
137137
h = hmac.new(b'key', message, hashlib.sha1) # O(n)
138138
digest = h.digest() # O(20) bytes
139139

140-
# SHA256: Default, secure
141-
# O(n) time (slower than MD5/SHA1)
140+
# SHA256: Common, secure choice
141+
# O(n) time
142142
h = hmac.new(b'key', message, hashlib.sha256) # O(n)
143143
digest = h.digest() # O(32) bytes
144144

145-
# SHA512: More secure, slower
145+
# SHA512: Larger digest size; performance varies by platform
146146
# O(n) time
147147
h = hmac.new(b'key', message, hashlib.sha512) # O(n)
148148
digest = h.digest() # O(64) bytes
@@ -209,7 +209,7 @@ if received_hmac == computed_hmac: # ❌ INSECURE
209209

210210
# Good: Constant-time comparison
211211
if hmac.compare_digest(received_hmac, computed_hmac): # ✓ SECURE
212-
# Always takes same time, timing independent
212+
# Timing-safe for equal-length inputs; time depends on length
213213
pass
214214
```
215215

@@ -373,8 +373,8 @@ import hashlib
373373
# Good balance of security and performance
374374
h = hmac.new(b'key', b'data', hashlib.sha256)
375375

376-
# SHA512: MAXIMUM SECURITY
377-
# Slower but better for critical applications
376+
# SHA512: Larger digest size
377+
# Performance varies by platform
378378
h = hmac.new(b'key', b'data', hashlib.sha512)
379379
```
380380

@@ -406,10 +406,7 @@ h = hmac.new(very_long_key, b'data', hashlib.sha256)
406406

407407
## Version Notes
408408

409-
- **Python 2.4+**: Basic HMAC support
410-
- **Python 3.4+**: `compare_digest()` function
411-
- **Python 3.6+**: Better performance
412-
- **Python 3.9+**: Additional algorithm support
409+
- **Python 3.x**: `hmac` module available, including `compare_digest()`
413410

414411
## Related Documentation
415412

docs/stdlib/html.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ The `html` module provides utilities for working with HTML content, including es
88
|-----------|------|-------|-------|
99
| `escape(text)` | O(n) | O(n) | n = string length |
1010
| `unescape(text)` | O(n) | O(n) | n = string length |
11-
| `parser.HTMLParser()` | O(n) | O(n) | n = HTML size |
12-
| `parser.feed(text)` | O(n) | O(n) | n = text length |
11+
| `html.parser.HTMLParser()` | O(1) | O(1) | Parser construction |
12+
| `HTMLParser.feed(text)` | O(n) | O(1) | n = text length; extra space depends on handlers |
1313

1414
## Common Operations
1515

@@ -47,7 +47,7 @@ unescaped = unescape(escaped)
4747
# Common entities - O(n)
4848
entities = '&copy; &nbsp; &#169; &#x00A9;'
4949
result = unescape(entities)
50-
# Returns: © © ©
50+
# Returns: ©  © ©
5151
```
5252

5353
## Common Use Cases
@@ -260,9 +260,7 @@ def get_title_safe(attrs):
260260

261261
## Version Notes
262262

263-
- **Python 3.2+**: html.escape() and unescape()
264-
- **Python 3.4+**: Improved html.parser
265-
- **Python 3.x**: Full Unicode support
263+
- **Python 3.x**: `html.escape`, `html.unescape`, and `html.parser` are available
266264

267265
## Related Documentation
268266

docs/stdlib/http.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ The `http` module provides HTTP client and server implementation, including stat
77
| Operation | Time | Space | Notes |
88
|-----------|------|-------|-------|
99
| Status lookup | O(1) | O(1) | Hash-based |
10-
| Parse message | O(n) | O(n) | n = message size |
1110

1211
## HTTP Status Codes
1312

@@ -21,7 +20,7 @@ print(HTTPStatus.OK) # 200
2120
print(HTTPStatus.NOT_FOUND) # 404
2221
print(HTTPStatus.FORBIDDEN) # 403
2322

24-
# Access by value - O(n) linear search through enum members
23+
# Access by value - O(1) lookup
2524
response_code = 404
2625
status = HTTPStatus(response_code)
2726
print(status.name) # NOT_FOUND

0 commit comments

Comments
 (0)