# Path: pre_commit_hooks/detect_private_key.py
# def main(argv: Sequence[str] | None = None) -> int:
#     parser = argparse.ArgumentParser()
#     parser.add_argument('filenames', nargs='*', help='Filenames to check')
#     args = parser.parse_args(argv)
# 
#     private_key_files = []
# 
#     for filename in args.filenames:
#         with open(filename, 'rb') as f:
#             content = f.read()
#             if any(line in content for line in BLACKLIST):
#                 private_key_files.append(filename)
# 
#     if private_key_files:
#         for private_key_file in private_key_files:
#             print(f'Private key found: {private_key_file}')
#         return 1
#     else:
#         return 0


import pytest
from pre_commit_hooks.detect_private_key import main
from __future__ import annotations



# Input, expected return value
TESTS = (
    (b'-----BEGIN RSA PRIVATE KEY-----', 1),
    (b'-----BEGIN DSA PRIVATE KEY-----', 1),
    (b'-----BEGIN EC PRIVATE KEY-----', 1),
    (b'-----BEGIN OPENSSH PRIVATE KEY-----', 1),
    (b'PuTTY-User-Key-File-2: ssh-rsa', 1),
    (b'---- BEGIN SSH2 ENCRYPTED PRIVATE KEY ----', 1),
    (b'-----BEGIN ENCRYPTED PRIVATE KEY-----', 1),
    (b'-----BEGIN OpenVPN Static key V1-----', 1),
    (b'ssh-rsa DATA', 0),
    (b'ssh-dsa DATA', 0),
    # Some arbitrary binary data
    (b'\xa2\xf1\x93\x12', 0),
)


@pytest.mark.parametrize(('input_s', 'expected_retval'), TESTS)
def test_main(input_s, expected_retval, tmpdir):
    path = tmpdir.join('file.txt')
    path.write_binary(input_s)

# Path: pre_commit_hooks/detect_private_key.py
# def main(argv: Sequence[str] | None = None) -> int:
#     parser = argparse.ArgumentParser()
#     parser.add_argument('filenames', nargs='*', help='Filenames to check')
#     args = parser.parse_args(argv)
# 
#     private_key_files = []
# 
#     for filename in args.filenames:
#         with open(filename, 'rb') as f:
#             content = f.read()
#             if any(line in content for line in BLACKLIST):
#                 private_key_files.append(filename)
# 
#     if private_key_files:
#         for private_key_file in private_key_files:
#             print(f'Private key found: {private_key_file}')
#         return 1
#     else:
#         return 0


# Path: tests/detect_private_key_test.py
import pytest
from pre_commit_hooks.detect_private_key import main

from __future__ import annotations



# Input, expected return value
TESTS = (
    (b'-----BEGIN RSA PRIVATE KEY-----', 1),
    (b'-----BEGIN DSA PRIVATE KEY-----', 1),
    (b'-----BEGIN EC PRIVATE KEY-----', 1),
    (b'-----BEGIN OPENSSH PRIVATE KEY-----', 1),
    (b'PuTTY-User-Key-File-2: ssh-rsa', 1),
    (b'---- BEGIN SSH2 ENCRYPTED PRIVATE KEY ----', 1),
    (b'-----BEGIN ENCRYPTED PRIVATE KEY-----', 1),
    (b'-----BEGIN OpenVPN Static key V1-----', 1),
    (b'ssh-rsa DATA', 0),
    (b'ssh-dsa DATA', 0),
    # Some arbitrary binary data
    (b'\xa2\xf1\x93\x12', 0),
)


@pytest.mark.parametrize(('input_s', 'expected_retval'), TESTS)
def test_main(input_s, expected_retval, tmpdir):
    path = tmpdir.join('file.txt')
    path.write_binary(input_s)

    assert main([str(path)]) == expected_retval