/** * Returns a flat name representation for this object. The name format is defined in RFC 2743: * * <pre> * Length Name Description * 2 TOK_ID Token Identifier * For exported name objects, this * must be hex 04 01. * 2 MECH_OID_LEN Length of the Mechanism OID * MECH_OID_LEN MECH_OID Mechanism OID, in DER * 4 NAME_LEN Length of name * NAME_LEN NAME Exported name; format defined in * applicable mechanism draft. * </pre> * * Note that it is not required to canonicalize a name before calling export(). i.e., the name * need not be an MN. If it is not an MN, an implementation defined algorithm can be used for * choosing the mechanism which should export this name. * * @return the flat name representation for this object * @exception GSSException with major codes NAME_NOT_MN, BAD_NAME, BAD_NAME, FAILURE. */ public byte[] export() throws GSSException { if (mechElement == null) { /* Use default mech */ mechElement = getElement(ProviderList.DEFAULT_MECH_OID); } byte[] mechPortion = mechElement.export(); byte[] oidBytes = null; ObjectIdentifier oid = null; try { oid = new ObjectIdentifier(mechElement.getMechanism().toString()); } catch (IOException e) { throw new GSSExceptionImpl(GSSException.FAILURE, "Invalid OID String "); } DerOutputStream dout = new DerOutputStream(); try { dout.putOID(oid); } catch (IOException e) { throw new GSSExceptionImpl(GSSException.FAILURE, "Could not ASN.1 Encode " + oid.toString()); } oidBytes = dout.toByteArray(); byte[] retVal = new byte[2 + 2 + oidBytes.length + 4 + mechPortion.length]; int pos = 0; retVal[pos++] = 0x04; retVal[pos++] = 0x01; retVal[pos++] = (byte) (oidBytes.length >>> 8); retVal[pos++] = (byte) oidBytes.length; System.arraycopy(oidBytes, 0, retVal, pos, oidBytes.length); pos += oidBytes.length; retVal[pos++] = (byte) (mechPortion.length >>> 24); retVal[pos++] = (byte) (mechPortion.length >>> 16); retVal[pos++] = (byte) (mechPortion.length >>> 8); retVal[pos++] = (byte) mechPortion.length; System.arraycopy(mechPortion, 0, retVal, pos, mechPortion.length); return retVal; }