1 20 21 22 package org.snmp4j.agent.mo.snmp; 23 24 import org.snmp4j.agent.*; 25 import org.snmp4j.agent.mo.*; 26 import org.snmp4j.security.*; 27 import org.snmp4j.smi.*; 28 import org.snmp4j.agent.request.SubRequest; 29 import org.snmp4j.mp.SnmpConstants; 30 31 public class KeyChange extends MOMutableColumn { 32 33 public KeyChange(int columnID, MOAccess access, 34 OctetString defaultValue, boolean mutableInService) { 35 super(columnID, SMIConstants.SYNTAX_OCTET_STRING, access, 36 defaultValue, mutableInService); 37 } 38 39 public static OctetString changeKey(AuthenticationProtocol authProtocol, 40 OctetString oldKey, 41 OctetString keyChange, 42 int keyLength) { 43 byte[] random = new byte[keyLength]; 44 byte[] delta = new byte[keyChange.length()-keyLength]; 45 57 58 System.arraycopy(keyChange.getValue(), 0, random, 0, keyLength); 59 System.arraycopy(keyChange.getValue(), keyLength, delta, 0, 60 keyChange.length()-keyLength); 61 byte[] newKey = authProtocol.changeDelta(oldKey.getValue(), delta, random); 62 return new OctetString(newKey, random.length, newKey.length - random.length); 63 } 65 66 public void get(SubRequest subRequest, MOTableRow row, int column) { 67 if (getAccess().isAccessibleForRead()) { 68 subRequest.getVariableBinding().setVariable(new OctetString()); 69 } 70 else { 71 subRequest.getStatus().setErrorStatus(SnmpConstants.SNMP_ERROR_NO_ACCESS); 72 } 73 subRequest.completed(); 74 } 75 76 } 77 | Popular Tags |