1 // NAME 2 // $RCSfile: AsnDecoderv2c.java,v $ 3 // DESCRIPTION 4 // [given below in javadoc format] 5 // DELTA 6 // $Revision: 3.3 $ 7 // CREATED 8 // $Date: 2006/02/09 14:16:36 $ 9 // COPYRIGHT 10 // Westhawk Ltd 11 // TO DO 12 // 13 14 /* 15 * Copyright (C) 1995, 1996 by West Consulting BV 16 * 17 * Permission to use, copy, modify, and distribute this software 18 * for any purpose and without fee is hereby granted, provided 19 * that the above copyright notices appear in all copies and that 20 * both the copyright notice and this permission notice appear in 21 * supporting documentation. 22 * This software is provided "as is" without express or implied 23 * warranty. 24 * original version by hargrave@dellgate.us.dell.com (Jordan Hargrave) 25 */ 26 27 /* 28 * Copyright (C) 1996 - 2006 by Westhawk Ltd 29 * <a href="www.westhawk.co.uk">www.westhawk.co.uk</a> 30 * 31 * Permission to use, copy, modify, and distribute this software 32 * for any purpose and without fee is hereby granted, provided 33 * that the above copyright notices appear in all copies and that 34 * both the copyright notice and this permission notice appear in 35 * supporting documentation. 36 * This software is provided "as is" without express or implied 37 * warranty. 38 * author <a href="mailto:snmp@westhawk.co.uk">Tim Panton</a> 39 */ 40 41 package uk.co.westhawk.snmp.stack; 42 43 /*- 44 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ 45 * SNMP Java Client 46 * ჻჻჻჻჻჻ 47 * Copyright 2023 MetricsHub, Westhawk 48 * ჻჻჻჻჻჻ 49 * This program is free software: you can redistribute it and/or modify 50 * it under the terms of the GNU Lesser General Public License as 51 * published by the Free Software Foundation, either version 3 of the 52 * License, or (at your option) any later version. 53 * 54 * This program is distributed in the hope that it will be useful, 55 * but WITHOUT ANY WARRANTY; without even the implied warranty of 56 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 57 * GNU General Lesser Public License for more details. 58 * 59 * You should have received a copy of the GNU General Lesser Public 60 * License along with this program. If not, see 61 * <http://www.gnu.org/licenses/lgpl-3.0.html>. 62 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ 63 */ 64 65 import uk.co.westhawk.snmp.util.*; 66 import java.io.*; 67 import java.util.*; 68 69 /** 70 * This class contains the v2c specific methods to decode bytes into a Pdu. 71 * We split the original class AsnDecoder into four classes. 72 * 73 * @since 4_14 74 * @author <a href="mailto:snmp@westhawk.co.uk">Tim Panton</a> 75 * @version $Revision: 3.3 $ $Date: 2006/02/09 14:16:36 $ 76 */ 77 class AsnDecoderv2c extends AsnDecoderBase { 78 private static final String version_id = "@(#)$Id: AsnDecoderv2c.java,v 3.3 2006/02/09 14:16:36 birgit Exp $ Copyright Westhawk Ltd"; 79 80 /** 81 * This method creates an AsnPduSequence out of the characters of the 82 * InputStream for v2c. 83 * 84 * @see AbstractSnmpContext#run 85 * @see SnmpContextv2c#processIncomingResponse 86 * @see SnmpContextv2c#processIncomingPdu 87 */ 88 AsnPduSequence DecodeSNMPv2c(InputStream in, String community) 89 throws IOException, DecodingException { 90 AsnSequence asnTopSeq = getAsnSequence(in); 91 int snmpVersion = getSNMPVersion(asnTopSeq); 92 if (snmpVersion != SnmpConstants.SNMP_VERSION_2c) { 93 String str = SnmpUtilities.getSnmpVersionString(snmpVersion); 94 String msg = "Wrong SNMP version: expected SNMPv2c, received " 95 + str; 96 throw new DecodingException(msg); 97 } 98 String comm = getCommunity(asnTopSeq); 99 if (comm.equals(community) == false) { 100 String msg = "Wrong community: expected " 101 + community + ", received " + comm; 102 throw new DecodingException(msg); 103 } 104 AsnPduSequence Pdu = (AsnPduSequence) asnTopSeq.findPdu(); 105 return Pdu; 106 } 107 108 }