From c6e6c105b05c0877143e9c9f196e4ee4cc87c9dc Mon Sep 17 00:00:00 2001 From: zhongpanpan <403712387@qq.com> Date: Fri, 21 Aug 2020 10:20:55 +0800 Subject: [PATCH] add tag in attribute --- .../tinyradius/attribute/RadiusAttribute.java | 52 +++++++++++++++++-- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/tinyradius/attribute/RadiusAttribute.java b/src/main/java/org/tinyradius/attribute/RadiusAttribute.java index 2059b79a..1947ffb5 100644 --- a/src/main/java/org/tinyradius/attribute/RadiusAttribute.java +++ b/src/main/java/org/tinyradius/attribute/RadiusAttribute.java @@ -147,6 +147,35 @@ public void setDictionary(Dictionary dictionary) { this.dictionary = dictionary; } + /** + * Sets the tag value of the attribute + * + * @param tag + * value of tag + */ + public void setTag(int tag) { + hasTag = true; + this.tag = tag; + } + + /** + * Returns the tag flag. + * + * @return tag flag + */ + public boolean hasTag() { + return hasTag; + } + + /** + * Returns the tag value. + * + * @return tag value + */ + public int getTag() { + return tag; + } + /** * Returns this attribute encoded as a byte array. * @@ -158,10 +187,20 @@ public byte[] writeAttribute() { if (attributeData == null) throw new NullPointerException("attribute data not set"); - byte[] attr = new byte[2 + attributeData.length]; - attr[0] = (byte) getAttributeType(); - attr[1] = (byte) (2 + attributeData.length); - System.arraycopy(attributeData, 0, attr, 2, attributeData.length); + byte[] attr = null; + if (!hasTag) { + attr = new byte[2 + attributeData.length]; + attr[0] = (byte) getAttributeType(); + attr[1] = (byte) (2 + attributeData.length); + System.arraycopy(attributeData, 0, attr, 2, attributeData.length); + } else { + attr = new byte[3 + attributeData.length]; + attr[0] = (byte) getAttributeType(); + attr[1] = (byte) (3 + attributeData.length); + attr[2] = (byte) (tag); + System.arraycopy(attributeData, 0, attr, 3, attributeData.length); + } + return attr; } @@ -295,4 +334,9 @@ public static RadiusAttribute createRadiusAttribute(int attributeType) { */ private byte[] attributeData = null; + /** + * tag info + */ + private int tag = 0; + private boolean hasTag = false; }