1 20 21 22 package org.snmp4j.agent.mo.snmp; 23 24 import org.snmp4j.agent.MOAccess; 25 import org.snmp4j.smi.OctetString; 26 import org.snmp4j.agent.request.SubRequest; 27 import org.snmp4j.agent.mo.MOTableRow; 28 import org.snmp4j.security.AuthenticationProtocol; 29 import org.snmp4j.PDU; 30 import org.snmp4j.security.PrivacyProtocol; 31 32 public class UsmKeyChange extends KeyChange { 33 34 public static final int AUTH_KEY_CHANGE = 0; 35 public static final int PRIV_KEY_CHANGE = 1; 36 37 private int type; 38 39 public UsmKeyChange(int columnID, 40 MOAccess access, int type) { 41 super(columnID, access, new OctetString(), true); 42 this.type = type; 43 } 44 45 public void prepare(SubRequest subRequest, MOTableRow row, 46 MOTableRow changeSet, int column) { 47 super.prepare(subRequest, row, changeSet, column); 48 if (!subRequest.hasError()) { 49 UsmMIB.UsmTableRow usmRow = (UsmMIB.UsmTableRow)row; 50 int digestLength = getDigestLength(usmRow, changeSet); 51 if (digestLength <= 0) { 52 subRequest.completed(); 53 return; 54 } 55 OctetString v = 56 (OctetString) subRequest.getVariableBinding().getVariable(); 57 if (v.length() != digestLength) { 58 subRequest.getStatus().setErrorStatus(PDU.wrongValue); 59 } 60 } 61 } 62 63 protected int getDigestLength(UsmMIB.UsmTableRow row, MOTableRow changeSet) { 64 switch (type) { 65 case AUTH_KEY_CHANGE: { 66 AuthenticationProtocol a = row.getAuthProtocol(changeSet); 67 if (a != null) { 68 return a.getDigestLength() * 2; 69 } 70 break; 71 } 72 case PRIV_KEY_CHANGE: { 73 PrivacyProtocol p = row.getPrivProtocol(changeSet); 74 if (p != null) { 75 return p.getMaxKeyLength() * 2; 76 } 77 break; 78 } 79 } 80 return -1; 81 } 82 83 public void commit(SubRequest subRequest, MOTableRow row, 84 MOTableRow changeSet, int column) { 85 int digestLength = getDigestLength((UsmMIB.UsmTableRow)row, changeSet); 86 if (digestLength > 0) { 87 super.commit(subRequest, row, changeSet, column); 88 } 89 else { 90 subRequest.completed(); 91 } 92 } 93 94 } 95 | Popular Tags |