Skip to content

Commit 2becb4b

Browse files
committed
Minor PEP8 fixes
1 parent e722b29 commit 2becb4b

3 files changed

Lines changed: 27 additions & 20 deletions

File tree

scapy/asn1/asn1.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def _fix(self, n=0):
9393
return o(GeneralizedTime()._fix())
9494
elif issubclass(o, ASN1_STRING):
9595
z1 = int(random.expovariate(0.05) + 1)
96-
return o("".join(random.choice(self.chars) for _ in range(z1)))
96+
return o("".join(random.choice(self.chars) for _ in range(z1)).encode())
9797
elif issubclass(o, ASN1_SEQUENCE) and (n < 10):
9898
z2 = int(random.expovariate(0.08) + 1)
9999
return o([self.__class__(objlist=self.objlist)._fix(n + 1)
@@ -520,7 +520,7 @@ def __repr__(self):
520520
)
521521

522522

523-
class ASN1_STRING(ASN1_Object[str]):
523+
class ASN1_STRING(ASN1_Object[bytes]):
524524
tag = ASN1_Class_UNIVERSAL.STRING
525525

526526

@@ -555,11 +555,11 @@ class ASN1_UTF8_STRING(ASN1_STRING):
555555
tag = ASN1_Class_UNIVERSAL.UTF8_STRING
556556

557557

558-
class ASN1_NUMERIC_STRING(ASN1_STRING):
558+
class ASN1_NUMERIC_STRING(ASN1_Object[str]):
559559
tag = ASN1_Class_UNIVERSAL.NUMERIC_STRING
560560

561561

562-
class ASN1_PRINTABLE_STRING(ASN1_STRING):
562+
class ASN1_PRINTABLE_STRING(ASN1_Object[str]):
563563
tag = ASN1_Class_UNIVERSAL.PRINTABLE_STRING
564564

565565

@@ -579,7 +579,7 @@ class ASN1_GENERAL_STRING(ASN1_STRING):
579579
tag = ASN1_Class_UNIVERSAL.GENERAL_STRING
580580

581581

582-
class ASN1_GENERALIZED_TIME(ASN1_STRING):
582+
class ASN1_GENERALIZED_TIME(ASN1_Object[str]):
583583
"""
584584
Improved version of ASN1_GENERALIZED_TIME, properly handling time zones and
585585
all string representation formats defined by ASN.1. These are:
@@ -723,7 +723,7 @@ def __repr__(self):
723723
# type: () -> str
724724
return "<%s[%r]>" % (
725725
self.__dict__.get("name", self.__class__.__name__),
726-
self.val.decode("utf-16be"), # type: ignore
726+
self.val.decode("utf-16be"),
727727
)
728728

729729

@@ -742,7 +742,7 @@ class ASN1_SET(ASN1_SEQUENCE):
742742
tag = ASN1_Class_UNIVERSAL.SET
743743

744744

745-
class ASN1_IPADDRESS(ASN1_STRING):
745+
class ASN1_IPADDRESS(ASN1_Object[str]):
746746
tag = ASN1_Class_UNIVERSAL.IPADDRESS
747747

748748

scapy/asn1fields.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ class ASN1F_STRING_PacketField(ASN1F_STRING):
981981
def i2m(self, pkt, val):
982982
# type: (ASN1_Packet, Any) -> bytes
983983
if hasattr(val, "ASN1_root"):
984-
val = ASN1_STRING(bytes(val)) # type: ignore
984+
val = ASN1_STRING(bytes(val))
985985
return super(ASN1F_STRING_PacketField, self).i2m(pkt, val)
986986

987987
def any2i(self, pkt, x):
@@ -1006,15 +1006,15 @@ def __init__(self,
10061006
):
10071007
# type: (...) -> None
10081008
self.cls = cls
1009-
super(ASN1F_STRING_ENCAPS, self).__init__( # type: ignore
1009+
super(ASN1F_STRING_ENCAPS, self).__init__(
10101010
name,
1011-
default and bytes(default),
1011+
default and bytes(default), # type: ignore
10121012
context=context,
10131013
implicit_tag=implicit_tag,
10141014
explicit_tag=explicit_tag
10151015
)
10161016

1017-
def m2i(self, pkt, s):
1018-
# type: (ASN1_Packet, bytes) -> Tuple[Optional[ASN1_Packet], bytes]
1017+
def m2i(self, pkt, s): # type: ignore
1018+
# type: (ASN1_Packet, bytes) -> Tuple[ASN1_Packet, bytes]
10191019
val = super(ASN1F_STRING_ENCAPS, self).m2i(pkt, s)
10201020
return self.cls(val[0].val, _underlayer=pkt), val[1]

scapy/layers/x509.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class RSAPrivateKey(ASN1_Packet):
122122
####################################
123123
# From X9.42 (or RFC3279)
124124

125+
125126
class ValidationParms(ASN1_Packet):
126127
ASN1_codec = ASN1_Codecs.BER
127128
ASN1_root = ASN1F_SEQUENCE(
@@ -1184,14 +1185,17 @@ class X509_CRL(ASN1_Packet):
11841185

11851186
# RFC3852 sect 5.2
11861187

1188+
# Other layers should store the structures that can be encapsulated
1189+
# by CMS here, referred by their OIDs.
11871190
_CMS_ENCAPSULATED = {}
11881191

1192+
11891193
class _EncapsulatedContent_Field(ASN1F_STRING_PacketField):
11901194
def m2i(self, pkt, s):
11911195
val = super(_EncapsulatedContent_Field, self).m2i(pkt, s)
11921196
if not val[0].val:
11931197
return val
1194-
1198+
11951199
# Get encapsulated value from its type
11961200
if pkt.eContentType.val in _CMS_ENCAPSULATED:
11971201
return (
@@ -1217,7 +1221,8 @@ class CMS_EncapsulatedContentInfo(ASN1_Packet):
12171221

12181222
class CMS_RevocationInfoChoice(ASN1_Packet):
12191223
ASN1_codec = ASN1_Codecs.BER
1220-
ASN1_root = ASN1F_CHOICE("crl", None,
1224+
ASN1_root = ASN1F_CHOICE(
1225+
"crl", None,
12211226
ASN1F_PACKET("crl", X509_CRL(), X509_Cert),
12221227
# -- TODO: 1
12231228
)
@@ -1227,11 +1232,13 @@ class CMS_RevocationInfoChoice(ASN1_Packet):
12271232

12281233
class CMS_CertificateChoices(ASN1_Packet):
12291234
ASN1_codec = ASN1_Codecs.BER
1230-
ASN1_root = ASN1F_CHOICE("certificate", None,
1235+
ASN1_root = ASN1F_CHOICE(
1236+
"certificate", None,
12311237
ASN1F_PACKET("certificate", X509_Cert(), X509_Cert),
12321238
# -- TODO: 0, 1, 2
12331239
)
12341240

1241+
12351242
# RFC3852 sect 10.2.4
12361243

12371244
class CMS_IssuerAndSerialNumber(ASN1_Packet):
@@ -1244,9 +1251,6 @@ class CMS_IssuerAndSerialNumber(ASN1_Packet):
12441251

12451252
# RFC3852 sect 5.3
12461253

1247-
CMS_SignerIdentifier = lambda name: ASN1F_CHOICE(name, None,
1248-
CMSVersion("version", 1),
1249-
)
12501254

12511255
class CMS_Attribute(ASN1_Packet):
12521256
ASN1_codec = ASN1_Codecs.BER
@@ -1261,7 +1265,8 @@ class CMS_SignerInfo(ASN1_Packet):
12611265
ASN1_root = ASN1F_SEQUENCE(
12621266
CMSVersion("version", 1),
12631267
ASN1F_PACKET("sid", CMS_IssuerAndSerialNumber(), CMS_IssuerAndSerialNumber),
1264-
ASN1F_PACKET("digestAlgorithm", X509_AlgorithmIdentifier(), X509_AlgorithmIdentifier),
1268+
ASN1F_PACKET("digestAlgorithm", X509_AlgorithmIdentifier(),
1269+
X509_AlgorithmIdentifier),
12651270
ASN1F_optional(
12661271
ASN1F_SET_OF(
12671272
"signedAttrs",
@@ -1270,7 +1275,8 @@ class CMS_SignerInfo(ASN1_Packet):
12701275
implicit_tag=0xA0,
12711276
)
12721277
),
1273-
ASN1F_PACKET("signatureAlgorithm", X509_AlgorithmIdentifier(), X509_AlgorithmIdentifier),
1278+
ASN1F_PACKET("signatureAlgorithm", X509_AlgorithmIdentifier(),
1279+
X509_AlgorithmIdentifier),
12741280
ASN1F_STRING("signature", ASN1_UTF8_STRING("")),
12751281
ASN1F_optional(
12761282
ASN1F_SET_OF(
@@ -1317,6 +1323,7 @@ class CMS_SignedData(ASN1_Packet):
13171323

13181324
# RFC3852 sect 3
13191325

1326+
13201327
class CMS_ContentInfo(ASN1_Packet):
13211328
ASN1_codec = ASN1_Codecs.BER
13221329
ASN1_root = ASN1F_SEQUENCE(

0 commit comments

Comments
 (0)