vsec 0.0.1

Detect secrets and in Rust codebases
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
//! SIMD-accelerated character classification functions.
//!
//! Provides vectorized implementations for checking if strings contain
//! only certain character classes (hex, base64, alphanumeric, etc.).

/// Check if all characters are ASCII hexadecimal digits [0-9a-fA-F].
#[inline]
pub fn is_all_hex(s: &str) -> bool {
    let bytes = s.as_bytes();

    if bytes.is_empty() {
        return true;
    }

    #[cfg(target_arch = "x86_64")]
    {
        if is_x86_feature_detected!("avx512bw") && bytes.len() >= 64 {
            return unsafe { is_all_hex_avx512(bytes) };
        }
        if is_x86_feature_detected!("avx2") && bytes.len() >= 32 {
            return unsafe { is_all_hex_avx2(bytes) };
        }
    }

    #[cfg(target_arch = "aarch64")]
    {
        if std::arch::is_aarch64_feature_detected!("neon") && bytes.len() >= 16 {
            return unsafe { is_all_hex_neon(bytes) };
        }
    }

    is_all_hex_scalar(bytes)
}

/// Scalar implementation for hex check.
#[inline]
fn is_all_hex_scalar(bytes: &[u8]) -> bool {
    bytes.iter().all(|&b| b.is_ascii_hexdigit())
}

/// AVX2 implementation for hex check.
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx2")]
unsafe fn is_all_hex_avx2(bytes: &[u8]) -> bool {
    use std::arch::x86_64::*;

    // Character ranges for hex: '0'-'9' (48-57), 'A'-'F' (65-70), 'a'-'f' (97-102)
    let digit_lo = _mm256_set1_epi8((b'0' - 1) as i8); // 47
    let digit_hi = _mm256_set1_epi8((b'9' + 1) as i8); // 58
    let upper_lo = _mm256_set1_epi8((b'A' - 1) as i8); // 64
    let upper_hi = _mm256_set1_epi8((b'F' + 1) as i8); // 71
    let lower_lo = _mm256_set1_epi8((b'a' - 1) as i8); // 96
    let lower_hi = _mm256_set1_epi8((b'f' + 1) as i8); // 103

    let chunks = bytes.len() / 32;
    let ptr = bytes.as_ptr();

    for i in 0..chunks {
        let data = _mm256_loadu_si256(ptr.add(i * 32) as *const __m256i);

        // Check if in range '0'-'9'
        let gt_digit_lo = _mm256_cmpgt_epi8(data, digit_lo);
        let lt_digit_hi = _mm256_cmpgt_epi8(digit_hi, data);
        let is_digit = _mm256_and_si256(gt_digit_lo, lt_digit_hi);

        // Check if in range 'A'-'F'
        let gt_upper_lo = _mm256_cmpgt_epi8(data, upper_lo);
        let lt_upper_hi = _mm256_cmpgt_epi8(upper_hi, data);
        let is_upper = _mm256_and_si256(gt_upper_lo, lt_upper_hi);

        // Check if in range 'a'-'f'
        let gt_lower_lo = _mm256_cmpgt_epi8(data, lower_lo);
        let lt_lower_hi = _mm256_cmpgt_epi8(lower_hi, data);
        let is_lower = _mm256_and_si256(gt_lower_lo, lt_lower_hi);

        // Combine: must be digit OR upper OR lower
        let is_hex = _mm256_or_si256(_mm256_or_si256(is_digit, is_upper), is_lower);

        // All bytes must be hex (all bits set = -1 = 0xFFFFFFFF)
        let mask = _mm256_movemask_epi8(is_hex);
        if mask != -1i32 {
            return false;
        }
    }

    // Check remainder
    is_all_hex_scalar(&bytes[chunks * 32..])
}

/// AVX-512 implementation for hex check.
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx512f", enable = "avx512bw")]
unsafe fn is_all_hex_avx512(bytes: &[u8]) -> bool {
    use std::arch::x86_64::*;

    let digit_lo = _mm512_set1_epi8((b'0' - 1) as i8);
    let digit_hi = _mm512_set1_epi8((b'9' + 1) as i8);
    let upper_lo = _mm512_set1_epi8((b'A' - 1) as i8);
    let upper_hi = _mm512_set1_epi8((b'F' + 1) as i8);
    let lower_lo = _mm512_set1_epi8((b'a' - 1) as i8);
    let lower_hi = _mm512_set1_epi8((b'f' + 1) as i8);

    let chunks = bytes.len() / 64;
    let ptr = bytes.as_ptr();

    for i in 0..chunks {
        let data = _mm512_loadu_si512(ptr.add(i * 64) as *const i32);

        // Check ranges using mask comparisons
        let is_digit = _mm512_cmpgt_epi8_mask(data, digit_lo) & _mm512_cmpgt_epi8_mask(digit_hi, data);
        let is_upper = _mm512_cmpgt_epi8_mask(data, upper_lo) & _mm512_cmpgt_epi8_mask(upper_hi, data);
        let is_lower = _mm512_cmpgt_epi8_mask(data, lower_lo) & _mm512_cmpgt_epi8_mask(lower_hi, data);

        let is_hex = is_digit | is_upper | is_lower;

        // All 64 bits must be set
        if is_hex != u64::MAX {
            return false;
        }
    }

    // Check remainder with AVX2 or scalar
    let remainder = &bytes[chunks * 64..];
    if remainder.len() >= 32 && is_x86_feature_detected!("avx2") {
        is_all_hex_avx2(remainder)
    } else {
        is_all_hex_scalar(remainder)
    }
}

/// NEON implementation for hex check.
#[cfg(target_arch = "aarch64")]
#[target_feature(enable = "neon")]
unsafe fn is_all_hex_neon(bytes: &[u8]) -> bool {
    use std::arch::aarch64::*;

    let chunks = bytes.len() / 16;
    let ptr = bytes.as_ptr();

    for i in 0..chunks {
        let data = vld1q_u8(ptr.add(i * 16));

        // Check ranges using NEON comparison
        let is_digit = vandq_u8(vcgeq_u8(data, vdupq_n_u8(b'0')), vcleq_u8(data, vdupq_n_u8(b'9')));
        let is_upper = vandq_u8(vcgeq_u8(data, vdupq_n_u8(b'A')), vcleq_u8(data, vdupq_n_u8(b'F')));
        let is_lower = vandq_u8(vcgeq_u8(data, vdupq_n_u8(b'a')), vcleq_u8(data, vdupq_n_u8(b'f')));

        let is_hex = vorrq_u8(vorrq_u8(is_digit, is_upper), is_lower);

        // Check if all bytes are 0xFF (valid hex)
        let min = vminvq_u8(is_hex);
        if min != 0xFF {
            return false;
        }
    }

    // Remainder
    is_all_hex_scalar(&bytes[chunks * 16..])
}

/// Check if all characters are valid base64 [A-Za-z0-9+/=].
#[inline]
pub fn is_all_base64_chars(s: &str) -> bool {
    let bytes = s.as_bytes();

    if bytes.is_empty() {
        return true;
    }

    #[cfg(target_arch = "x86_64")]
    {
        if is_x86_feature_detected!("avx2") && bytes.len() >= 32 {
            return unsafe { is_all_base64_avx2(bytes) };
        }
    }

    #[cfg(target_arch = "aarch64")]
    {
        if std::arch::is_aarch64_feature_detected!("neon") && bytes.len() >= 16 {
            return unsafe { is_all_base64_neon(bytes) };
        }
    }

    is_all_base64_scalar(bytes)
}

/// Scalar implementation for base64 check.
#[inline]
fn is_all_base64_scalar(bytes: &[u8]) -> bool {
    bytes.iter().all(|&b| {
        b.is_ascii_alphanumeric() || b == b'+' || b == b'/' || b == b'='
    })
}

/// AVX2 implementation for base64 check.
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx2")]
unsafe fn is_all_base64_avx2(bytes: &[u8]) -> bool {
    use std::arch::x86_64::*;

    // Ranges: A-Z (65-90), a-z (97-122), 0-9 (48-57), + (43), / (47), = (61)
    let upper_lo = _mm256_set1_epi8((b'A' - 1) as i8);
    let upper_hi = _mm256_set1_epi8((b'Z' + 1) as i8);
    let lower_lo = _mm256_set1_epi8((b'a' - 1) as i8);
    let lower_hi = _mm256_set1_epi8((b'z' + 1) as i8);
    let digit_lo = _mm256_set1_epi8((b'0' - 1) as i8);
    let digit_hi = _mm256_set1_epi8((b'9' + 1) as i8);
    let plus = _mm256_set1_epi8(b'+' as i8);
    let slash = _mm256_set1_epi8(b'/' as i8);
    let equals = _mm256_set1_epi8(b'=' as i8);

    let chunks = bytes.len() / 32;
    let ptr = bytes.as_ptr();

    for i in 0..chunks {
        let data = _mm256_loadu_si256(ptr.add(i * 32) as *const __m256i);

        // Check ranges
        let is_upper = _mm256_and_si256(
            _mm256_cmpgt_epi8(data, upper_lo),
            _mm256_cmpgt_epi8(upper_hi, data),
        );
        let is_lower = _mm256_and_si256(
            _mm256_cmpgt_epi8(data, lower_lo),
            _mm256_cmpgt_epi8(lower_hi, data),
        );
        let is_digit = _mm256_and_si256(
            _mm256_cmpgt_epi8(data, digit_lo),
            _mm256_cmpgt_epi8(digit_hi, data),
        );
        let is_plus = _mm256_cmpeq_epi8(data, plus);
        let is_slash = _mm256_cmpeq_epi8(data, slash);
        let is_equals = _mm256_cmpeq_epi8(data, equals);

        // Combine all valid options
        let is_alpha = _mm256_or_si256(is_upper, is_lower);
        let is_alnum = _mm256_or_si256(is_alpha, is_digit);
        let is_special = _mm256_or_si256(_mm256_or_si256(is_plus, is_slash), is_equals);
        let is_valid = _mm256_or_si256(is_alnum, is_special);

        let mask = _mm256_movemask_epi8(is_valid);
        if mask != -1i32 {
            return false;
        }
    }

    is_all_base64_scalar(&bytes[chunks * 32..])
}

/// NEON implementation for base64 check.
#[cfg(target_arch = "aarch64")]
#[target_feature(enable = "neon")]
unsafe fn is_all_base64_neon(bytes: &[u8]) -> bool {
    use std::arch::aarch64::*;

    let chunks = bytes.len() / 16;
    let ptr = bytes.as_ptr();

    for i in 0..chunks {
        let data = vld1q_u8(ptr.add(i * 16));

        // Check ranges
        let is_upper = vandq_u8(vcgeq_u8(data, vdupq_n_u8(b'A')), vcleq_u8(data, vdupq_n_u8(b'Z')));
        let is_lower = vandq_u8(vcgeq_u8(data, vdupq_n_u8(b'a')), vcleq_u8(data, vdupq_n_u8(b'z')));
        let is_digit = vandq_u8(vcgeq_u8(data, vdupq_n_u8(b'0')), vcleq_u8(data, vdupq_n_u8(b'9')));
        let is_plus = vceqq_u8(data, vdupq_n_u8(b'+'));
        let is_slash = vceqq_u8(data, vdupq_n_u8(b'/'));
        let is_equals = vceqq_u8(data, vdupq_n_u8(b'='));

        let is_alpha = vorrq_u8(is_upper, is_lower);
        let is_alnum = vorrq_u8(is_alpha, is_digit);
        let is_special = vorrq_u8(vorrq_u8(is_plus, is_slash), is_equals);
        let is_valid = vorrq_u8(is_alnum, is_special);

        let min = vminvq_u8(is_valid);
        if min != 0xFF {
            return false;
        }
    }

    is_all_base64_scalar(&bytes[chunks * 16..])
}

/// Check if string matches UUID format (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
#[inline]
pub fn is_uuid_format(s: &str) -> bool {
    let bytes = s.as_bytes();

    // UUID is exactly 36 characters
    if bytes.len() != 36 {
        return false;
    }

    // Check dash positions: 8, 13, 18, 23
    if bytes[8] != b'-' || bytes[13] != b'-' || bytes[18] != b'-' || bytes[23] != b'-' {
        return false;
    }

    // Check all other positions are hex (case-insensitive)
    for (i, &b) in bytes.iter().enumerate() {
        match i {
            8 | 13 | 18 | 23 => continue,
            _ => {
                if !b.is_ascii_hexdigit() {
                    return false;
                }
            }
        }
    }

    true
}

/// Check if string contains any uppercase ASCII letter.
#[inline]
pub fn has_uppercase(s: &str) -> bool {
    let bytes = s.as_bytes();

    #[cfg(target_arch = "x86_64")]
    {
        if is_x86_feature_detected!("avx2") && bytes.len() >= 32 {
            return unsafe { has_uppercase_avx2(bytes) };
        }
    }

    #[cfg(target_arch = "aarch64")]
    {
        if std::arch::is_aarch64_feature_detected!("neon") && bytes.len() >= 16 {
            return unsafe { has_uppercase_neon(bytes) };
        }
    }

    bytes.iter().any(|&b| b.is_ascii_uppercase())
}

/// AVX2 implementation for uppercase detection.
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx2")]
unsafe fn has_uppercase_avx2(bytes: &[u8]) -> bool {
    use std::arch::x86_64::*;

    let upper_lo = _mm256_set1_epi8((b'A' - 1) as i8);
    let upper_hi = _mm256_set1_epi8((b'Z' + 1) as i8);

    let chunks = bytes.len() / 32;
    let ptr = bytes.as_ptr();

    for i in 0..chunks {
        let data = _mm256_loadu_si256(ptr.add(i * 32) as *const __m256i);

        let is_upper = _mm256_and_si256(
            _mm256_cmpgt_epi8(data, upper_lo),
            _mm256_cmpgt_epi8(upper_hi, data),
        );

        let mask = _mm256_movemask_epi8(is_upper);
        if mask != 0 {
            return true;
        }
    }

    // Check remainder
    bytes[chunks * 32..].iter().any(|&b| b.is_ascii_uppercase())
}

/// NEON implementation for uppercase detection.
#[cfg(target_arch = "aarch64")]
#[target_feature(enable = "neon")]
unsafe fn has_uppercase_neon(bytes: &[u8]) -> bool {
    use std::arch::aarch64::*;

    let chunks = bytes.len() / 16;
    let ptr = bytes.as_ptr();

    for i in 0..chunks {
        let data = vld1q_u8(ptr.add(i * 16));

        let is_upper = vandq_u8(vcgeq_u8(data, vdupq_n_u8(b'A')), vcleq_u8(data, vdupq_n_u8(b'Z')));

        let max = vmaxvq_u8(is_upper);
        if max != 0 {
            return true;
        }
    }

    bytes[chunks * 16..].iter().any(|&b| b.is_ascii_uppercase())
}

/// Check if string contains any lowercase ASCII letter.
#[inline]
pub fn has_lowercase(s: &str) -> bool {
    let bytes = s.as_bytes();

    #[cfg(target_arch = "x86_64")]
    {
        if is_x86_feature_detected!("avx2") && bytes.len() >= 32 {
            return unsafe { has_lowercase_avx2(bytes) };
        }
    }

    #[cfg(target_arch = "aarch64")]
    {
        if std::arch::is_aarch64_feature_detected!("neon") && bytes.len() >= 16 {
            return unsafe { has_lowercase_neon(bytes) };
        }
    }

    bytes.iter().any(|&b| b.is_ascii_lowercase())
}

/// AVX2 implementation for lowercase detection.
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx2")]
unsafe fn has_lowercase_avx2(bytes: &[u8]) -> bool {
    use std::arch::x86_64::*;

    let lower_lo = _mm256_set1_epi8((b'a' - 1) as i8);
    let lower_hi = _mm256_set1_epi8((b'z' + 1) as i8);

    let chunks = bytes.len() / 32;
    let ptr = bytes.as_ptr();

    for i in 0..chunks {
        let data = _mm256_loadu_si256(ptr.add(i * 32) as *const __m256i);

        let is_lower = _mm256_and_si256(
            _mm256_cmpgt_epi8(data, lower_lo),
            _mm256_cmpgt_epi8(lower_hi, data),
        );

        let mask = _mm256_movemask_epi8(is_lower);
        if mask != 0 {
            return true;
        }
    }

    bytes[chunks * 32..].iter().any(|&b| b.is_ascii_lowercase())
}

/// NEON implementation for lowercase detection.
#[cfg(target_arch = "aarch64")]
#[target_feature(enable = "neon")]
unsafe fn has_lowercase_neon(bytes: &[u8]) -> bool {
    use std::arch::aarch64::*;

    let chunks = bytes.len() / 16;
    let ptr = bytes.as_ptr();

    for i in 0..chunks {
        let data = vld1q_u8(ptr.add(i * 16));

        let is_lower = vandq_u8(vcgeq_u8(data, vdupq_n_u8(b'a')), vcleq_u8(data, vdupq_n_u8(b'z')));

        let max = vmaxvq_u8(is_lower);
        if max != 0 {
            return true;
        }
    }

    bytes[chunks * 16..].iter().any(|&b| b.is_ascii_lowercase())
}

/// Check if all characters are ASCII alphanumeric.
#[inline]
pub fn is_all_alphanumeric(s: &str) -> bool {
    let bytes = s.as_bytes();

    if bytes.is_empty() {
        return true;
    }

    #[cfg(target_arch = "x86_64")]
    {
        if is_x86_feature_detected!("avx2") && bytes.len() >= 32 {
            return unsafe { is_all_alphanumeric_avx2(bytes) };
        }
    }

    #[cfg(target_arch = "aarch64")]
    {
        if std::arch::is_aarch64_feature_detected!("neon") && bytes.len() >= 16 {
            return unsafe { is_all_alphanumeric_neon(bytes) };
        }
    }

    bytes.iter().all(|&b| b.is_ascii_alphanumeric())
}

/// AVX2 implementation for alphanumeric check.
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx2")]
unsafe fn is_all_alphanumeric_avx2(bytes: &[u8]) -> bool {
    use std::arch::x86_64::*;

    let upper_lo = _mm256_set1_epi8((b'A' - 1) as i8);
    let upper_hi = _mm256_set1_epi8((b'Z' + 1) as i8);
    let lower_lo = _mm256_set1_epi8((b'a' - 1) as i8);
    let lower_hi = _mm256_set1_epi8((b'z' + 1) as i8);
    let digit_lo = _mm256_set1_epi8((b'0' - 1) as i8);
    let digit_hi = _mm256_set1_epi8((b'9' + 1) as i8);

    let chunks = bytes.len() / 32;
    let ptr = bytes.as_ptr();

    for i in 0..chunks {
        let data = _mm256_loadu_si256(ptr.add(i * 32) as *const __m256i);

        let is_upper = _mm256_and_si256(
            _mm256_cmpgt_epi8(data, upper_lo),
            _mm256_cmpgt_epi8(upper_hi, data),
        );
        let is_lower = _mm256_and_si256(
            _mm256_cmpgt_epi8(data, lower_lo),
            _mm256_cmpgt_epi8(lower_hi, data),
        );
        let is_digit = _mm256_and_si256(
            _mm256_cmpgt_epi8(data, digit_lo),
            _mm256_cmpgt_epi8(digit_hi, data),
        );

        let is_valid = _mm256_or_si256(_mm256_or_si256(is_upper, is_lower), is_digit);

        let mask = _mm256_movemask_epi8(is_valid);
        if mask != -1i32 {
            return false;
        }
    }

    bytes[chunks * 32..].iter().all(|&b| b.is_ascii_alphanumeric())
}

/// NEON implementation for alphanumeric check.
#[cfg(target_arch = "aarch64")]
#[target_feature(enable = "neon")]
unsafe fn is_all_alphanumeric_neon(bytes: &[u8]) -> bool {
    use std::arch::aarch64::*;

    let chunks = bytes.len() / 16;
    let ptr = bytes.as_ptr();

    for i in 0..chunks {
        let data = vld1q_u8(ptr.add(i * 16));

        let is_upper = vandq_u8(vcgeq_u8(data, vdupq_n_u8(b'A')), vcleq_u8(data, vdupq_n_u8(b'Z')));
        let is_lower = vandq_u8(vcgeq_u8(data, vdupq_n_u8(b'a')), vcleq_u8(data, vdupq_n_u8(b'z')));
        let is_digit = vandq_u8(vcgeq_u8(data, vdupq_n_u8(b'0')), vcleq_u8(data, vdupq_n_u8(b'9')));

        let is_valid = vorrq_u8(vorrq_u8(is_upper, is_lower), is_digit);

        let min = vminvq_u8(is_valid);
        if min != 0xFF {
            return false;
        }
    }

    bytes[chunks * 16..].iter().all(|&b| b.is_ascii_alphanumeric())
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_is_all_hex() {
        assert!(is_all_hex("0123456789abcdef"));
        assert!(is_all_hex("ABCDEF"));
        assert!(is_all_hex("aAbBcCdDeEfF"));
        assert!(is_all_hex(""));
        assert!(!is_all_hex("0123456789abcdefg"));
        assert!(!is_all_hex("hello"));
        assert!(!is_all_hex("0123456789abcdef "));
    }

    #[test]
    fn test_is_all_hex_long() {
        let hex = "a".repeat(1000);
        assert!(is_all_hex(&hex));

        let mut not_hex = "a".repeat(999);
        not_hex.push('g');
        assert!(!is_all_hex(&not_hex));
    }

    #[test]
    fn test_is_all_base64_chars() {
        assert!(is_all_base64_chars("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="));
        assert!(is_all_base64_chars("SGVsbG8gV29ybGQh"));
        assert!(is_all_base64_chars("dGVzdA=="));
        assert!(is_all_base64_chars(""));
        assert!(!is_all_base64_chars("invalid!"));
        assert!(!is_all_base64_chars("has space "));
    }

    #[test]
    fn test_is_uuid_format() {
        assert!(is_uuid_format("550e8400-e29b-41d4-a716-446655440000"));
        assert!(is_uuid_format("AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE"));
        assert!(is_uuid_format("00000000-0000-0000-0000-000000000000"));
        assert!(!is_uuid_format("not-a-uuid"));
        assert!(!is_uuid_format("550e8400-e29b-41d4-a716-44665544000")); // too short
        assert!(!is_uuid_format("550e8400-e29b-41d4-a716-4466554400000")); // too long
        assert!(!is_uuid_format("550e8400e29b-41d4-a716-446655440000")); // wrong dash
        assert!(!is_uuid_format("550e8400-e29b-41d4-a716-44665544000g")); // invalid char
    }

    #[test]
    fn test_has_uppercase() {
        assert!(has_uppercase("Hello"));
        assert!(has_uppercase("HELLO"));
        assert!(has_uppercase("helloA"));
        assert!(!has_uppercase("hello"));
        assert!(!has_uppercase("123"));
        assert!(!has_uppercase(""));
    }

    #[test]
    fn test_has_lowercase() {
        assert!(has_lowercase("Hello"));
        assert!(has_lowercase("hello"));
        assert!(has_lowercase("HELLOa"));
        assert!(!has_lowercase("HELLO"));
        assert!(!has_lowercase("123"));
        assert!(!has_lowercase(""));
    }

    #[test]
    fn test_is_all_alphanumeric() {
        assert!(is_all_alphanumeric("Hello123"));
        assert!(is_all_alphanumeric("HELLO"));
        assert!(is_all_alphanumeric("12345"));
        assert!(is_all_alphanumeric(""));
        assert!(!is_all_alphanumeric("Hello World"));
        assert!(!is_all_alphanumeric("hello-world"));
        assert!(!is_all_alphanumeric("test_123"));
    }

    #[test]
    fn test_long_strings() {
        // Test SIMD paths with long strings
        let long_hex = "a".repeat(1000);
        assert!(is_all_hex(&long_hex));

        let long_alpha = "A".repeat(500) + &"a".repeat(500);
        assert!(is_all_alphanumeric(&long_alpha));
        assert!(has_uppercase(&long_alpha));
        assert!(has_lowercase(&long_alpha));
    }

    #[test]
    fn test_simd_scalar_equivalence() {
        // Test that SIMD and scalar give same results for various lengths
        for len in [0, 1, 15, 16, 31, 32, 63, 64, 100, 1000] {
            let s: String = (0..len).map(|i| (b'a' + (i % 6) as u8) as char).collect();
            assert_eq!(
                is_all_hex(&s),
                is_all_hex_scalar(s.as_bytes()),
                "Mismatch at length {} for hex",
                len
            );
        }
    }
}