Code Duplication    Length = 32-32 lines in 2 locations

gvm/protocols/gmpv7.py 1 location

@@ 1281-1312 (lines=32) @@
1278
            _xmlkey = cmd.add_element("key")
1279
            _xmlkey.add_element("private", private_key)
1280
1281
        if credential_type == CredentialType.SNMP:
1282
            if not isinstance(auth_algorithm, SnmpAuthAlgorithm):
1283
                raise InvalidArgument(
1284
                    "create_credential requires auth_algorithm to be a "
1285
                    "SnmpAuthAlgorithm instance",
1286
                    function="create_credential",
1287
                    argument="auth_algorithm",
1288
                )
1289
1290
            cmd.add_element("auth_algorithm", auth_algorithm.value)
1291
1292
            if community:
1293
                cmd.add_element("community", community)
1294
1295
            if privacy_algorithm is not None or privacy_password:
1296
                _xmlprivacy = cmd.add_element("privacy")
1297
1298
                if privacy_algorithm is not None:
1299
                    if not isinstance(privacy_algorithm, SnmpPrivacyAlgorithm):
1300
                        raise InvalidArgument(
1301
                            "create_credential requires algorithm to be a "
1302
                            "SnmpPrivacyAlgorithm instance",
1303
                            function="create_credential",
1304
                            argument="privacy_algorithm",
1305
                        )
1306
1307
                    _xmlprivacy.add_element(
1308
                        "algorithm", privacy_algorithm.value
1309
                    )
1310
1311
                if privacy_password:
1312
                    _xmlprivacy.add_element("password", privacy_password)
1313
1314
        return self._send_xml_command(cmd)
1315

gvm/protocols/gmpv8.py 1 location

@@ 511-542 (lines=32) @@
508
            _xmlkey = cmd.add_element("key")
509
            _xmlkey.add_element("private", private_key)
510
511
        if credential_type == CredentialType.SNMP:
512
            if not isinstance(auth_algorithm, SnmpAuthAlgorithm):
513
                raise InvalidArgument(
514
                    "create_credential requires auth_algorithm to be a "
515
                    "SnmpAuthAlgorithm instance",
516
                    function="create_credential",
517
                    argument="auth_algorithm",
518
                )
519
520
            cmd.add_element("auth_algorithm", auth_algorithm.value)
521
522
            if community:
523
                cmd.add_element("community", community)
524
525
            if privacy_algorithm is not None or privacy_password:
526
                _xmlprivacy = cmd.add_element("privacy")
527
528
                if privacy_algorithm is not None:
529
                    if not isinstance(privacy_algorithm, SnmpPrivacyAlgorithm):
530
                        raise InvalidArgument(
531
                            "create_credential requires algorithm to be a "
532
                            "SnmpPrivacyAlgorithm instance",
533
                            function="create_credential",
534
                            argument="privacy_algorithm",
535
                        )
536
537
                    _xmlprivacy.add_element(
538
                        "algorithm", privacy_algorithm.value
539
                    )
540
541
                if privacy_password:
542
                    _xmlprivacy.add_element("password", privacy_password)
543
544
        if credential_type == CredentialType.PGP_ENCRYPTION_KEY:
545
            if not public_key: