1 package org.metricshub.ipmi.core.coding; 2 3 /*- 4 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ 5 * IPMI Java Client 6 * ჻჻჻჻჻჻ 7 * Copyright 2023 Verax Systems, MetricsHub 8 * ჻჻჻჻჻჻ 9 * This program is free software: you can redistribute it and/or modify 10 * it under the terms of the GNU Lesser General Public License as 11 * published by the Free Software Foundation, either version 3 of the 12 * License, or (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Lesser Public License for more details. 18 * 19 * You should have received a copy of the GNU General Lesser Public 20 * License along with this program. If not, see 21 * <http://www.gnu.org/licenses/lgpl-3.0.html>. 22 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ 23 */ 24 25 import org.metricshub.ipmi.core.coding.commands.ResponseData; 26 import org.metricshub.ipmi.core.coding.payload.CompletionCode; 27 import org.metricshub.ipmi.core.coding.payload.lan.IPMIException; 28 import org.metricshub.ipmi.core.coding.protocol.decoder.IpmiDecoder; 29 import org.metricshub.ipmi.core.coding.protocol.decoder.PlainCommandv20Decoder; 30 import org.metricshub.ipmi.core.coding.protocol.decoder.Protocolv15Decoder; 31 import org.metricshub.ipmi.core.coding.protocol.decoder.Protocolv20Decoder; 32 import org.metricshub.ipmi.core.coding.rmcp.RmcpDecoder; 33 34 import java.security.InvalidKeyException; 35 import java.security.NoSuchAlgorithmException; 36 37 /** 38 * Decodes RMCP packet into {@link ResponseData}. 39 */ 40 public final class Decoder { 41 42 /** 43 * Decodes raw data into {@link ResponseData} - a wrapper class for 44 * message-specific response data. 45 * 46 * @param data 47 * - raw RMCP packet to be decoded 48 * @param protocolDecoder 49 * - instance of {@link IpmiDecoder} class for decoding of the 50 * IPMI session header and (if present) IPMI LAN packet. If IPMI 51 * LAN packet is present, {@link Protocolv15Decoder} or 52 * {@link Protocolv20Decoder} should be used (depending on IPMI 53 * protocol version used). Otherwise, 54 * {@link PlainCommandv20Decoder} should be used. 55 * @param payloadCoder 56 * - instance of {@link PayloadCoder} class used for wrapping 57 * payload into message-dependent {@link ResponseData} object. 58 * @return {@link ResponseData} 59 * @throws IPMIException 60 * when request to the server fails. 61 * @see CompletionCode 62 * @throws IllegalArgumentException 63 * when data is corrupted 64 * @throws NoSuchAlgorithmException 65 * - when authentication, confidentiality or integrity algorithm 66 * fails. 67 * @throws InvalidKeyException 68 * when creating of the authentication algorithm key fails 69 */ 70 public static ResponseData decode(byte[] data, IpmiDecoder protocolDecoder, 71 PayloadCoder payloadCoder) throws IPMIException, NoSuchAlgorithmException, InvalidKeyException { 72 return payloadCoder.getResponseData(protocolDecoder.decode(RmcpDecoder 73 .decode(data))); 74 } 75 76 private Decoder() { 77 } 78 }