ServerKeyExchange class with more robust formatting capability.
| 222 | |
| 223 | |
| 224 | class ServerKeyExchange(messages.ServerKeyExchange): |
| 225 | """ServerKeyExchange class with more robust formatting capability.""" |
| 226 | |
| 227 | def parse(self, parser): |
| 228 | """more robust parser for SKE""" |
| 229 | try: |
| 230 | super(ServerKeyExchange, self).parse(parser) |
| 231 | except AssertionError: |
| 232 | pass |
| 233 | return self |
| 234 | |
| 235 | def __format__(self, formatstr): |
| 236 | """Return human-readable representation of the object.""" |
| 237 | if 'v' in formatstr: |
| 238 | verbose = "CipherSuite." |
| 239 | else: |
| 240 | verbose = "" |
| 241 | |
| 242 | ret = "ServerKeyExchange(cipherSuite={0}{1}, version={2}"\ |
| 243 | .format(verbose, CipherSuite.ietfNames[self.cipherSuite], |
| 244 | self.version) |
| 245 | if self.srp_N: |
| 246 | ret += ", srp_N={0}, srp_g={1}, srp_s={2}, srp_B={3}"\ |
| 247 | .format(self.srp_N, self.srp_g, self.srp_s, self.srp_B) |
| 248 | if self.dh_p: |
| 249 | ret += ", dh_p={0}, dh_g={1}, dh_Ys={2}"\ |
| 250 | .format(self.dh_p, self.dh_g, self.dh_Ys) |
| 251 | if self.ecdh_Ys: |
| 252 | ecdh_Ys = format_bytearray(self.ecdh_Ys, formatstr) |
| 253 | ret += ", curve_type={0}, named_curve={1}, ecdh_Ys={2}"\ |
| 254 | .format(ECCurveType.toStr(self.curve_type), |
| 255 | GroupName.toStr(self.named_curve), ecdh_Ys) |
| 256 | if self.signAlg: |
| 257 | ret += ", hashAlg={0}, signAlg={1}"\ |
| 258 | .format(HashAlgorithm.toStr(self.hashAlg), |
| 259 | SignatureAlgorithm.toStr(self.signAlg)) |
| 260 | if self.signature: |
| 261 | ret += ", signature={0}"\ |
| 262 | .format(format_bytearray(self.signature, formatstr)) |
| 263 | |
| 264 | return ret + ")" |