Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 48 additions & 4 deletions src/main/java/org/tinyradius/attribute/RadiusAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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;
}

Expand Down Expand Up @@ -295,4 +334,9 @@ public static RadiusAttribute createRadiusAttribute(int attributeType) {
*/
private byte[] attributeData = null;

/**
* tag info
*/
private int tag = 0;
private boolean hasTag = false;
}