mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-07 04:26:52 +00:00
Merge pull request #76 from chriskuehl/private-key-print-only-filename
detect_private_key: print *filenames*, not the key
This commit is contained in:
commit
003e43251a
2 changed files with 11 additions and 5 deletions
|
|
@ -3,6 +3,12 @@ from __future__ import print_function
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
BLACKLIST = [
|
||||||
|
b'BEGIN RSA PRIVATE KEY',
|
||||||
|
b'BEGIN DSA PRIVATE KEY',
|
||||||
|
b'BEGIN EC PRIVATE KEY',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def detect_private_key(argv=None):
|
def detect_private_key(argv=None):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
@ -12,11 +18,10 @@ def detect_private_key(argv=None):
|
||||||
private_key_files = []
|
private_key_files = []
|
||||||
|
|
||||||
for filename in args.filenames:
|
for filename in args.filenames:
|
||||||
content = open(filename, 'rb').read()
|
with open(filename, 'rb') as f:
|
||||||
if b'BEGIN RSA PRIVATE KEY' in content:
|
content = f.read()
|
||||||
private_key_files.append(content)
|
if any(line in content for line in BLACKLIST):
|
||||||
if b'BEGIN DSA PRIVATE KEY' in content:
|
private_key_files.append(filename)
|
||||||
private_key_files.append(content)
|
|
||||||
|
|
||||||
if private_key_files:
|
if private_key_files:
|
||||||
for private_key_file in private_key_files:
|
for private_key_file in private_key_files:
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ from pre_commit_hooks.detect_private_key import detect_private_key
|
||||||
TESTS = (
|
TESTS = (
|
||||||
(b'-----BEGIN RSA PRIVATE KEY-----', 1),
|
(b'-----BEGIN RSA PRIVATE KEY-----', 1),
|
||||||
(b'-----BEGIN DSA PRIVATE KEY-----', 1),
|
(b'-----BEGIN DSA PRIVATE KEY-----', 1),
|
||||||
|
(b'-----BEGIN EC PRIVATE KEY-----', 1),
|
||||||
(b'ssh-rsa DATA', 0),
|
(b'ssh-rsa DATA', 0),
|
||||||
(b'ssh-dsa DATA', 0),
|
(b'ssh-dsa DATA', 0),
|
||||||
# Some arbitrary binary data
|
# Some arbitrary binary data
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue