Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
django-sshkey
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
043fe297
authored
Jul 01, 2014
by
Scott Duckworth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename SSHKeyFormatError to PublicKeyParseError
parent
3550b54a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
10 deletions
+10
-10
django_sshkey/models.py
+2
-2
django_sshkey/util.py
+8
-8
No files found.
django_sshkey/models.py
View file @
043fe297
...
...
@@ -29,7 +29,7 @@
from
django.db
import
models
from
django.contrib.auth.models
import
User
from
django.core.exceptions
import
ValidationError
from
django_sshkey.util
import
SSHKeyFormat
Error
,
pubkey_parse
from
django_sshkey.util
import
PublicKeyParse
Error
,
pubkey_parse
class
UserKey
(
models
.
Model
):
user
=
models
.
ForeignKey
(
User
,
db_index
=
True
)
...
...
@@ -55,7 +55,7 @@ class UserKey(models.Model):
def
clean
(
self
):
try
:
pubkey
=
pubkey_parse
(
self
.
key
)
except
SSHKeyFormat
Error
as
e
:
except
PublicKeyParse
Error
as
e
:
raise
ValidationError
(
str
(
e
))
self
.
key
=
pubkey
.
format_openssh
()
self
.
fingerprint
=
pubkey
.
fingerprint
()
...
...
django_sshkey/util.py
View file @
043fe297
...
...
@@ -52,7 +52,7 @@ def wrap(text, width, wrap_end=None):
n
=
m
return
t
class
SSHKeyFormat
Error
(
Exception
):
class
PublicKeyParse
Error
(
Exception
):
def
__init__
(
self
,
text
):
self
.
text
=
text
...
...
@@ -90,16 +90,16 @@ class PublicKey(object):
def
pubkey_parse_openssh
(
text
):
fields
=
text
.
split
(
None
,
2
)
if
len
(
fields
)
<
2
:
raise
SSHKeyFormat
Error
(
text
)
raise
PublicKeyParse
Error
(
text
)
try
:
if
len
(
fields
)
==
2
:
key
=
PublicKey
(
fields
[
1
])
else
:
key
=
PublicKey
(
fields
[
1
],
fields
[
2
])
except
TypeError
:
raise
SSHKeyFormat
Error
(
text
)
raise
PublicKeyParse
Error
(
text
)
if
fields
[
0
]
!=
key
.
algorithm
:
raise
SSHKeyFormat
Error
(
text
)
raise
PublicKeyParse
Error
(
text
)
return
key
def
pubkey_parse_rfc4716
(
text
):
...
...
@@ -108,7 +108,7 @@ def pubkey_parse_rfc4716(text):
lines
[
0
]
==
'---- BEGIN SSH2 PUBLIC KEY ----'
and
lines
[
-
1
]
==
'---- END SSH2 PUBLIC KEY ----'
):
raise
SSHKeyFormat
Error
(
text
)
raise
PublicKeyParse
Error
(
text
)
lines
=
lines
[
1
:
-
1
]
b64key
=
''
headers
=
{}
...
...
@@ -127,7 +127,7 @@ def pubkey_parse_rfc4716(text):
try
:
return
PublicKey
(
b64key
,
comment
)
except
TypeError
:
raise
SSHKeyFormat
Error
(
text
)
raise
PublicKeyParse
Error
(
text
)
def
pubkey_parse
(
text
):
lines
=
text
.
splitlines
()
...
...
@@ -138,7 +138,7 @@ def pubkey_parse(text):
if
lines
[
0
]
==
'---- BEGIN SSH2 PUBLIC KEY ----'
:
return
pubkey_parse_rfc4716
(
text
)
raise
SSHKeyFormat
Error
(
text
)
raise
PublicKeyParse
Error
(
text
)
def
lookup_all
(
url
):
import
urllib
...
...
@@ -190,7 +190,7 @@ def lookup_by_fingerprint_main():
sys
.
exit
(
1
)
try
:
pubkey
=
pubkey_parse
(
key
)
except
SSHKeyFormat
Error
as
e
:
except
PublicKeyParse
Error
as
e
:
sys
.
stderr
.
write
(
"Error: "
+
str
(
e
))
sys
.
exit
(
1
)
fingerprint
=
pubkey
.
fingerprint
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment