From bf6a68e86481d1f9b01ed8c06ff73d1c3585a943 Mon Sep 17 00:00:00 2001 From: David Blacka Date: Fri, 29 Mar 2024 20:32:05 -0400 Subject: [PATCH] sonarlint changes --- .../dnssec/security/BINDKeyUtils.java | 23 +++++++-------- .../verisignlabs/dnssec/security/TypeMap.java | 28 +++++++++---------- .../dnssec/security/ZoneUtils.java | 19 +++++-------- 3 files changed, 33 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/verisignlabs/dnssec/security/BINDKeyUtils.java b/src/main/java/com/verisignlabs/dnssec/security/BINDKeyUtils.java index 450f8d4..c9a00d1 100644 --- a/src/main/java/com/verisignlabs/dnssec/security/BINDKeyUtils.java +++ b/src/main/java/com/verisignlabs/dnssec/security/BINDKeyUtils.java @@ -46,7 +46,8 @@ import org.xbill.DNS.utils.base64; */ public class BINDKeyUtils { - private BINDKeyUtils() { } + private BINDKeyUtils() { + } /** * Calculate the BIND9 key file base name (i.e., without the ".key" or @@ -60,18 +61,18 @@ public class BINDKeyUtils { /** Reads in the DNSKEYRecord from the public key file */ private static DNSKEYRecord loadPublicKeyFile(File publicKeyFile) throws IOException { - Master m = new Master(publicKeyFile.getAbsolutePath(), null, 600); + try (Master m = new Master(publicKeyFile.getAbsolutePath(), null, 600)) { + Record r; + DNSKEYRecord result = null; - Record r; - DNSKEYRecord result = null; - - while ((r = m.nextRecord()) != null) { - if (r.getType() == Type.DNSKEY) { - result = (DNSKEYRecord) r; + while ((r = m.nextRecord()) != null) { + if (r.getType() == Type.DNSKEY) { + result = (DNSKEYRecord) r; + } } - } - return result; + return result; + } } /** Reads in the private key verbatim from the private key file */ @@ -272,7 +273,7 @@ public class BINDKeyUtils { try { DnsKeyConverter conv = new DnsKeyConverter(); return conv.parsePrivateKeyString(privateKeyString); - } catch (IOException|NoSuchAlgorithmException e) { + } catch (IOException | NoSuchAlgorithmException e) { e.printStackTrace(); } diff --git a/src/main/java/com/verisignlabs/dnssec/security/TypeMap.java b/src/main/java/com/verisignlabs/dnssec/security/TypeMap.java index 84542cd..d4a8bea 100644 --- a/src/main/java/com/verisignlabs/dnssec/security/TypeMap.java +++ b/src/main/java/com/verisignlabs/dnssec/security/TypeMap.java @@ -37,7 +37,7 @@ public class TypeMap { private Set typeSet; public TypeMap() { - this.typeSet = new HashSet(); + this.typeSet = new HashSet<>(); } /** Add the given type to the typemap. */ @@ -78,20 +78,20 @@ public class TypeMap { TypeMap typemap = new TypeMap(); int page; - int byte_length; + int byteLength; while (m < map.length) { page = map[m++]; - byte_length = map[m++]; + byteLength = map[m++]; - for (int i = 0; i < byte_length; i++) { + for (int i = 0; i < byteLength; i++) { for (int j = 0; j < 8; j++) { - if ((map[m + i] & (1 << (7 - j))) != 0) { + if (((map[m + i] & 0xFF) & (1 << (7 - j))) != 0) { typemap.set((page << 8) + (i * 8) + j); } } } - m += byte_length; + m += byteLength; } return typemap; @@ -115,7 +115,7 @@ public class TypeMap { int[] types = getTypes(); Arrays.sort(types); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (int i = 0; i < types.length; i++) { if (i > 0) @@ -129,16 +129,16 @@ public class TypeMap { protected static void mapToWire(DNSOutput out, int[] types, int base, int start, int end) { // calculate the length of this map by looking at the largest // typecode in this section. - int max_type = types[end - 1] & 0xFF; - int map_length = (max_type / 8) + 1; + int maxType = types[end - 1] & 0xFF; + int mapLength = (maxType / 8) + 1; // write the map "header" -- the base and the length of the map. out.writeU8(base & 0xFF); - out.writeU8(map_length & 0xFF); + out.writeU8(mapLength & 0xFF); // allocate a temporary scratch space for caculating the actual // bitmap. - byte[] map = new byte[map_length]; + byte[] map = new byte[mapLength]; // for each type in our sub-array, set its corresponding bit in the map. for (int i = start; i < end; i++) { @@ -179,7 +179,7 @@ public class TypeMap { } public int[] getTypes() { - Integer[] a = (Integer[]) typeSet.toArray(integerArray); + Integer[] a = typeSet.toArray(integerArray); int[] res = new int[a.length]; for (int i = 0; i < res.length; i++) { @@ -189,8 +189,8 @@ public class TypeMap { return res; } - public static int[] fromWireToTypes(byte[] wire_fmt) { - return TypeMap.fromBytes(wire_fmt).getTypes(); + public static int[] fromWireToTypes(byte[] wireFmt) { + return TypeMap.fromBytes(wireFmt).getTypes(); } public static byte[] fromTypesToWire(int[] types) { diff --git a/src/main/java/com/verisignlabs/dnssec/security/ZoneUtils.java b/src/main/java/com/verisignlabs/dnssec/security/ZoneUtils.java index 209c27d..5729197 100644 --- a/src/main/java/com/verisignlabs/dnssec/security/ZoneUtils.java +++ b/src/main/java/com/verisignlabs/dnssec/security/ZoneUtils.java @@ -39,6 +39,10 @@ import org.xbill.DNS.Type; */ public class ZoneUtils { + + private ZoneUtils() { + } + /** * Load a zone file. * @@ -53,19 +57,10 @@ public class ZoneUtils { * if something goes wrong reading the zone file. */ public static List readZoneFile(String zonefile, Name origin) throws IOException { - ArrayList records = new ArrayList(); - Master m; - try { - if (zonefile.equals("-")) { - m = new Master(System.in); - } else { - m = new Master(zonefile, origin); - } - + ArrayList records = new ArrayList<>(); + try (Master m = zonefile.equals("-") ? new Master(System.in) : new Master(zonefile, origin)) { Record r = null; - while ((r = m.nextRecord()) != null) { - records.add(r); } } catch (IOException e) { @@ -120,7 +115,7 @@ public class ZoneUtils { } public static List findRRs(List records, Name name, int type) { - List res = new ArrayList(); + List res = new ArrayList<>(); for (Record r : records) { if (r.getName().equals(name) && r.getType() == type) { res.add(r);