@Test public void convert() { boolean[] bits; bits = new boolean[] {false, false, false, false, false, false, false, false, false }; Set<KeyUsage> usages = keyUsageConverter.convert(bits); assertEquals(new HashSet<>(usages), new HashSet<>()); bits = new boolean[] {true, false, false, false, false, false, false, false, true }; usages = keyUsageConverter.convert(bits); assertEquals(new HashSet<>(usages), new HashSet<>(Arrays.asList( KeyUsage.DIGITAL_SIGNATURE, KeyUsage.DECIPHER_ONLY))); bits = new boolean[] {false, true, false, false, false, false, false, true, false }; usages = keyUsageConverter.convert(bits); assertEquals(new HashSet<>(usages), new HashSet<>(Arrays.asList( KeyUsage.NON_REPUDIATION, KeyUsage.ENCIPHER_ONLY))); bits = new boolean[] {false, false, false, false, true, false, false, false, false }; usages = keyUsageConverter.convert(bits); assertEquals(new HashSet<>(usages), new HashSet<>(Arrays.asList( KeyUsage.KEY_AGREEMENT))); bits = new boolean[] {false, false, false, false, true }; usages = keyUsageConverter.convert(bits); assertEquals(new HashSet<>(usages), new HashSet<>(Arrays.asList( KeyUsage.KEY_AGREEMENT))); bits = new boolean[] {}; usages = keyUsageConverter.convert(bits); assertEquals(new HashSet<>(usages), new HashSet<>()); bits = new boolean[] {false, false, false, false, false, false, false, false, true, true, true, true }; usages = keyUsageConverter.convert(bits); assertEquals(new HashSet<>(usages), new HashSet<>(Arrays.asList( KeyUsage.DECIPHER_ONLY))); }
public EnumSet<KeyUsage> convert(boolean[] keyUsageBits) { EnumSet<KeyUsage> usages = EnumSet.noneOf(KeyUsage.class); if (keyUsageBits != null) { for (int i = 0; i < Math.min(BIT_TO_USAGE.size(), keyUsageBits.length); i++) { if (keyUsageBits[i]) { usages.add(BIT_TO_USAGE.get(i)); } } } return usages; }
KeyUsageConverter { public EnumSet<KeyUsage> convert(boolean[] keyUsageBits) { EnumSet<KeyUsage> usages = EnumSet.noneOf(KeyUsage.class); if (keyUsageBits != null) { for (int i = 0; i < Math.min(BIT_TO_USAGE.size(), keyUsageBits.length); i++) { if (keyUsageBits[i]) { usages.add(BIT_TO_USAGE.get(i)); } } } return usages; } }
KeyUsageConverter { public EnumSet<KeyUsage> convert(boolean[] keyUsageBits) { EnumSet<KeyUsage> usages = EnumSet.noneOf(KeyUsage.class); if (keyUsageBits != null) { for (int i = 0; i < Math.min(BIT_TO_USAGE.size(), keyUsageBits.length); i++) { if (keyUsageBits[i]) { usages.add(BIT_TO_USAGE.get(i)); } } } return usages; }  }
KeyUsageConverter { public EnumSet<KeyUsage> convert(boolean[] keyUsageBits) { EnumSet<KeyUsage> usages = EnumSet.noneOf(KeyUsage.class); if (keyUsageBits != null) { for (int i = 0; i < Math.min(BIT_TO_USAGE.size(), keyUsageBits.length); i++) { if (keyUsageBits[i]) { usages.add(BIT_TO_USAGE.get(i)); } } } return usages; }  EnumSet<KeyUsage> convert(boolean[] keyUsageBits); }
KeyUsageConverter { public EnumSet<KeyUsage> convert(boolean[] keyUsageBits) { EnumSet<KeyUsage> usages = EnumSet.noneOf(KeyUsage.class); if (keyUsageBits != null) { for (int i = 0; i < Math.min(BIT_TO_USAGE.size(), keyUsageBits.length); i++) { if (keyUsageBits[i]) { usages.add(BIT_TO_USAGE.get(i)); } } } return usages; }  EnumSet<KeyUsage> convert(boolean[] keyUsageBits);  }