/** * Checks whether bit n of the supplied OctetString is set or not. * @param n * denotes the bit to check starting from zero. * @param os OctetString * @return boolean */ public static boolean isBitSet(final int n, final OctetString os) { return (os.length() <= n / 8) || ((os.get(n / 8) & (0x01 << (7 - (n % 8)))) > 0); }
/** * Checks whether bit n of the supplied OctetString is set or not. * @param n * denotes the bit to check starting from zero. * @param os OctetString * @return boolean */ private static boolean isBitSet(final int n, final OctetString os) { if (os.length() <= n/8) { return true; } return (os.get(n/8) & (0x01 << (7 - (n % 8)))) > 0; }
/** * Returns a copy of this OctetString where each bit not set in the supplied * mask zeros the corresponding bit in the returned OctetString. * @param mask * a mask where the n-th bit corresponds to the n-th bit in the returned * OctetString. * @return * the masked OctetString. * @since 1.7 */ public OctetString mask(OctetString mask) { byte[] masked = new byte[value.length]; System.arraycopy(value, 0, masked, 0, value.length); for (int i=0; (i<mask.length()) && (i<masked.length); i++) { masked[i] = (byte)(masked[i] & mask.get(i)); } return new OctetString(masked); }
/** * Returns a copy of this OID where sub-identifiers have been set to zero * for all n-th sub-identifier where the n-th bit of mask is zero. * @param mask * a mask where the n-th bit corresponds to the n-th sub-identifier. * @return * the masked OID. * @since 1.5 */ public OID mask(OctetString mask) { int[] masked = new int[value.length]; System.arraycopy(value, 0, masked, 0, value.length); for (int i=0; (i<mask.length()*8) && (i<masked.length); i++) { byte b = (byte) (0x80 >> (i%8)); if ((mask.get(i/8) & b) == 0) { masked[i] = 0; } } return new OID(masked); }
/** * Returns a copy of this OID where sub-identifiers have been set to zero * for all n-th sub-identifier where the n-th bit of mask is zero. * @param mask * a mask where the n-th bit corresponds to the n-th sub-identifier. * @return * the masked OID. * @since 1.5 */ public OID mask(OctetString mask) { int[] masked = new int[value.length]; System.arraycopy(value, 0, masked, 0, value.length); for (int i=0; (i<mask.length()*8) && (i<masked.length); i++) { byte b = (byte) (0x80 >> (i%8)); if ((mask.get(i/8) & b) == 0) { masked[i] = 0; } } return new OID(masked); }
/** * Returns a copy of this OID where sub-identifiers have been set to zero * for all n-th sub-identifier where the n-th bit of mask is zero. * * @param mask a mask where the n-th bit corresponds to the n-th sub-identifier. * @return the masked OID. * @since 1.5 */ public OID mask(OctetString mask) { int[] masked = new int[value.length]; System.arraycopy(value, 0, masked, 0, value.length); for (int i = 0; (i < mask.length() * 8) && (i < masked.length); i++) { byte b = (byte) (0x80 >> (i % 8)); if ((mask.get(i / 8) & b) == 0) { masked[i] = 0; } } return new OID(masked); }
/** * Returns a copy of this OctetString where each bit not set in the supplied * mask zeros the corresponding bit in the returned OctetString. * @param mask * a mask where the n-th bit corresponds to the n-th bit in the returned * OctetString. * @return * the masked OctetString. * @since 1.7 */ public OctetString mask(OctetString mask) { byte[] masked = new byte[value.length]; System.arraycopy(value, 0, masked, 0, value.length); for (int i=0; (i<mask.length()) && (i<masked.length); i++) { masked[i] = (byte)(masked[i] & mask.get(i)); } return new OctetString(masked); }
/** * Returns a copy of this OctetString where each bit not set in the supplied * mask zeros the corresponding bit in the returned OctetString. * @param mask * a mask where the n-th bit corresponds to the n-th bit in the returned * OctetString. * @return * the masked OctetString. * @since 1.7 */ public OctetString mask(OctetString mask) { byte[] masked = new byte[value.length]; System.arraycopy(value, 0, masked, 0, value.length); for (int i=0; (i<mask.length()) && (i<masked.length); i++) { masked[i] = (byte)(masked[i] & mask.get(i)); } return new OctetString(masked); }
public int hashCode() { if (context != null) { int hash = super.hashCode(); // One-at-a-time Hash adapted from Bob Jenkins for (int i = 0; i < context.length(); i++) { hash += context.get(i); hash += (hash << 10); hash ^= (hash >> 6); } hash += (hash << 3); hash ^= (hash >> 11); hash += (hash << 15); return hash; } return super.hashCode(); }
public int hashCode() { if (context != null) { int hash = super.hashCode(); // One-at-a-time Hash adapted from Bob Jenkins for (int i = 0; i < context.length(); i++) { hash += context.get(i); hash += (hash << 10); hash ^= (hash >> 6); } hash += (hash << 3); hash ^= (hash >> 11); hash += (hash << 15); return hash; } return super.hashCode(); }
/** * Tests if this octet string starts with the specified prefix. * @param prefix * the prefix. * @return * {@code true} if the bytes of this octet string up to the length * of {@code prefix} equal those of {@code prefix}. * @since 1.2 */ public boolean startsWith(OctetString prefix) { if ((prefix == null) || prefix.length() > length()) { return false; } for (int i=0; i<prefix.length(); i++) { if (prefix.get(i) != value[i]) { return false; } } return true; }
public static int isValidTagValue(Variable newValue) { if (!(newValue instanceof OctetString)) { return SnmpConstants.SNMP_ERROR_WRONG_TYPE; } int status = SnmpConstants.SNMP_ERROR_SUCCESS; OctetString os = (OctetString)newValue; if (os.length() > 255) { status = SnmpConstants.SNMP_ERROR_WRONG_LENGTH; } else { for (int i = 0; i < os.length(); i++) { if (isDelimiter(os.get(i))) { status = SnmpConstants.SNMP_ERROR_BAD_VALUE; break; } } } return status; }
/** * Tests if this octet string starts with the specified prefix. * @param prefix * the prefix. * @return * {@code true} if the bytes of this octet string up to the length * of {@code prefix} equal those of {@code prefix}. * @since 1.2 */ public boolean startsWith(OctetString prefix) { if ((prefix == null) || prefix.length() > length()) { return false; } for (int i=0; i<prefix.length(); i++) { if (prefix.get(i) != value[i]) { return false; } } return true; }
public OID toSubIndex(boolean impliedLength) { int[] subIndex; int offset = 0; if (!impliedLength) { subIndex = new int[length()+1]; subIndex[offset++] = length(); } else { subIndex = new int[length()]; } for (int i=0; i<length(); i++) { subIndex[offset+i] = get(i) & 0xFF; } return new OID(subIndex); }
public OID toSubIndex(boolean impliedLength) { int[] subIndex; int offset = 0; if (!impliedLength) { subIndex = new int[length()+1]; subIndex[offset++] = length(); } else { subIndex = new int[length()]; } for (int i=0; i<length(); i++) { subIndex[offset+i] = get(i) & 0xFF; } return new OID(subIndex); }
public OID toSubIndex(boolean impliedLength) { int[] subIndex; int offset = 0; if (!impliedLength) { subIndex = new int[length()+1]; subIndex[offset++] = length(); } else { subIndex = new int[length()]; } for (int i=0; i<length(); i++) { subIndex[offset+i] = get(i) & 0xFF; } return new OID(subIndex); }
private List getViews(OctetString viewName) { if (viewName.length() == 0) { return Collections.EMPTY_LIST; } OctetString upperBound = new OctetString(viewName); byte last = upperBound.get(upperBound.length()-1); if (last == -1) { upperBound.append((byte)0); } else { upperBound.set(upperBound.length()-1, (byte)(last+1)); } OID lowerOID = viewName.toSubIndex(false); OID upperOID = upperBound.toSubIndex(false); List views = vacmViewTreeFamilyTableModel.getRows(lowerOID, upperOID); return views; }
private List<MOTableRow> getAccessEntries(OctetString groupName) { OctetString upperBound = new OctetString(groupName); byte last = -1; if (upperBound.length() > 0) { last = upperBound.get(upperBound.length() - 1); } if (last == -1) { upperBound.append((byte)0); } else { upperBound.set(upperBound.length()-1, (byte)(last+1)); } OID lowerOID = groupName.toSubIndex(false); OID upperOID = upperBound.toSubIndex(false); return vacmAccessTableModel.getRows(lowerOID, upperOID); }
protected List getViews(OctetString viewName) { if (viewName.length() == 0) { return Collections.EMPTY_LIST; } OctetString upperBound = new OctetString(viewName); byte last = upperBound.get(upperBound.length()-1); if (last == -1) { upperBound.append((byte)0); } else { upperBound.set(upperBound.length()-1, (byte)(last+1)); } OID lowerOID = viewName.toSubIndex(false); OID upperOID = upperBound.toSubIndex(false); return vacmViewTreeFamilyTableModel.getRows(lowerOID, upperOID); }
private List getAccessEntries(OctetString groupName) { OctetString upperBound = new OctetString(groupName); byte last = -1; if (upperBound.length() > 0) { last = upperBound.get(upperBound.length() - 1); } if (last == -1) { upperBound.append((byte)0); } else { upperBound.set(upperBound.length()-1, (byte)(last+1)); } OID lowerOID = groupName.toSubIndex(false); OID upperOID = upperBound.toSubIndex(false); List views = vacmAccessTableModel.getRows(lowerOID, upperOID); return views; }