Package org.nasutekds.server.types

Examples of org.nasutekds.server.types.ByteStringBuilder$SubSequence


   */
  @Test(dataProvider = "elementArrays")
  public void testDecodeValidArrayAsOctetStringBuilder(byte[] b)
      throws Exception
  {
    ByteStringBuilder bsb = new ByteStringBuilder();
    bsb.append(ASN1Constants.UNIVERSAL_OCTET_STRING_TYPE);
    bsb.appendBERLength(b.length);
    bsb.append(b);

    ByteStringBuilder bsb2 = new ByteStringBuilder();
    getReader(bsb.toByteArray(), 0).readOctetString(bsb2);
    assertEquals(bsb2.toByteString(), ByteString.wrap(b));
  }
View Full Code Here


   */
  @Test(dataProvider = "elementArrays")
  public void testDecodeValidArrayAsSequence(byte[] encodedElements)
      throws Exception
  {
    ByteStringBuilder bsb = new ByteStringBuilder();
    bsb.append(ASN1Constants.UNIVERSAL_SEQUENCE_TYPE);
    bsb.appendBERLength(encodedElements.length + 2);
    bsb.append(ASN1Constants.UNIVERSAL_OCTET_STRING_TYPE);
    bsb.appendBERLength(encodedElements.length);
    bsb.append(encodedElements);

    ASN1Reader reader = getReader(bsb.toByteArray(), 0);
    assertEquals(reader.peekLength(), encodedElements.length + 2);
    reader.readStartSequence();
    assertEquals(reader.peekType(), ASN1Constants.UNIVERSAL_OCTET_STRING_TYPE);
    assertEquals(reader.peekLength(), encodedElements.length);
    reader.readOctetString().equals(ByteString.wrap(encodedElements));
View Full Code Here

   */
  @Test(dataProvider = "binaryValues")
  public void testEncodeDecodeOctetStringType(byte[] b) throws Exception
  {
    ByteString bs = ByteString.wrap(b);
    ByteStringBuilder bsb = new ByteStringBuilder();

    for(byte type : testTypes)
    {
      bsb.clear();
      getWriter().writeOctetString(type, bs);

      ASN1Reader r = getReader(getEncodedBytes());
      assertEquals(r.peekLength(), b.length);
      assertEquals(r.peekType(), type);
      r.readOctetString(bsb);
      assertTrue(bs.equals(bsb));

      bsb.clear();
      getWriter().writeOctetString(type, b, 0, b.length);

      r = getReader(getEncodedBytes());
      assertEquals(r.peekLength(), b.length);
      assertEquals(r.peekType(), type);
View Full Code Here

  protected byte[] encodeMods(List<Modification> mods)
  {
    if ((mods == null) || (mods.size() == 0))
      return new byte[0];

    ByteStringBuilder byteBuilder = new ByteStringBuilder();
    ASN1Writer writer = ASN1.getWriter(byteBuilder);

    for (Modification mod : mods)
    {
      Attribute attr = mod.getAttribute();
      AttributeType type = attr.getAttributeType();
      if (type != null )
      {
        if (AttributeUsage.DSA_OPERATION.equals(type.getUsage()))
        {
          // Attributes with a dsaOperation usage should not be synchronized.
          // skip them.
          continue;
        }
      }

      if (!EntryHistorical.isHistoricalAttribute(attr))
      {
        LDAPModification ldapmod = new LDAPModification(
          mod.getModificationType(), new LDAPAttribute(mod.getAttribute()));
        try
        {
          ldapmod.write(writer);
        }
        catch(Exception e)
        {
          // DO SOMETHING
        }
      }
    }
    return byteBuilder.toByteArray();
  }
View Full Code Here

  public byte[] getBytes(short protocolVersion)
     throws UnsupportedEncodingException
  {
    try
    {
      ByteStringBuilder byteBuilder = new ByteStringBuilder();
      ASN1Writer writer = ASN1.getWriter(byteBuilder);

      if (protocolVersion > ProtocolVersion.REPLICATION_PROTOCOL_V1)
      {
        /* put the type of the operation */
        byteBuilder.append(MSG_TYPE_REPL_SERVER_MONITOR);

        /*
         * V4 and above uses integers for its serverIds while V2 and V3
         * use shorts.
         */
        if (protocolVersion >= ProtocolVersion.REPLICATION_PROTOCOL_V4)
        {
          byteBuilder.append(senderID);
          byteBuilder.append(destination);
        }
        else
        {
          byteBuilder.append((short)senderID);
          byteBuilder.append((short)destination);
        }
      }

      /* Put the serverStates ... */
      writer.writeStartSequence();

      /* first put the Replication Server state */
      writer.writeStartSequence();
      ArrayList<ByteString> cnOctetList =
        data.replServerDbState.toASN1ArrayList();
      for (ByteString soci : cnOctetList)
      {
        writer.writeOctetString(soci);
      }
      writer.writeEndSequence();

      // then the LDAP server datas
      Set<Integer> servers = data.ldapStates.keySet();
      for (Integer sid : servers)
      {
        ServerState statei = data.ldapStates.get(sid).state;
        Long outime = data.ldapStates.get(sid).approxFirstMissingDate;

        // retrieves the change numbers as an arrayList of ANSN1OctetString
        cnOctetList = statei.toASN1ArrayList();

        writer.writeStartSequence();
        // a fake changenumber helps storing the LDAP server ID
        ChangeNumber cn = new ChangeNumber(outime,1,sid);
        writer.writeOctetString(cn.toString());

        // the changenumbers that make the state
        for (ByteString soci : cnOctetList)
        {
          writer.writeOctetString(soci);
        }

        writer.writeEndSequence();
      }

      // then the RS server datas
      servers = data.rsStates.keySet();
      for (Integer sid : servers)
      {
        ServerState statei = data.rsStates.get(sid).state;
        Long outime = data.rsStates.get(sid).approxFirstMissingDate;

        // retrieves the change numbers as an arrayList of ANSN1OctetString
        cnOctetList = statei.toASN1ArrayList();

        writer.writeStartSequence();
        // a fake changenumber helps storing the LDAP server ID
        ChangeNumber cn = new ChangeNumber(outime,0,sid);
        writer.writeOctetString(cn.toString());

        // the changenumbers that make the state
        for (ByteString soci : cnOctetList)
        {
          writer.writeOctetString(soci);
        }

        writer.writeEndSequence();
      }

      writer.writeEndSequence();

      if (protocolVersion > ProtocolVersion.REPLICATION_PROTOCOL_V1)
      {
        return byteBuilder.toByteArray();
      }
      else
      {
        byte[] temp = byteBuilder.toByteArray();

        byte[] senderBytes = String.valueOf(senderID).getBytes("UTF-8");
        byte[] destinationBytes = String.valueOf(destination).getBytes("UTF-8");

        int length = 1 1 + senderBytes.length +
View Full Code Here

  private byte[] getBytes_V4()
  {
    try
    {
      ByteStringBuilder byteBuilder = new ByteStringBuilder();
      ASN1Writer writer = ASN1.getWriter(byteBuilder);

      byteBuilder.append(MSG_TYPE_START_SESSION);
      byteBuilder.append(status.getValue());
      byteBuilder.append(assuredFlag ? (byte) 1 : (byte) 0);
      byteBuilder.append(assuredMode.getValue());
      byteBuilder.append(safeDataLevel);

      writer.writeStartSequence();
      for (String url : referralsURLs)
        writer.writeOctetString(url);
      writer.writeEndSequence();

      writer.writeStartSequence();
      for (String attrDef : eclIncludes)
        writer.writeOctetString(attrDef);
      writer.writeEndSequence();

      return byteBuilder.toByteArray();
    }
    catch (Exception e)
    {
      return null;
    }
View Full Code Here

   {
     if (attributes==null)
       return new byte[0];
     try
     {
       ByteStringBuilder byteBuilder = new ByteStringBuilder();
       ASN1Writer writer = ASN1.getWriter(byteBuilder);
       for (Attribute a : attributes)
       {
         new LDAPAttribute(a).write(writer);
       }
       return byteBuilder.toByteArray();
     }
     catch (Exception e)
     {
       return null;
     }
View Full Code Here

   *
   * @return  The ASN.1 octet string containing the encoded connection ID.
   */
  public static ByteString encodeResponseValue(long connectionID)
  {
    ByteStringBuilder builder = new ByteStringBuilder(8);
    ASN1Writer writer = ASN1.getWriter(builder);

    try
    {
      writer.writeInteger(connectionID);
    }
    catch(Exception e)
    {
      if (debugEnabled())
      {
        TRACER.debugCaught(DebugLogLevel.ERROR, e);
      }
    }

    return builder.toByteString();
  }
View Full Code Here

      throws DirectoryException
  {
    DN dn = prefix;
    int start = offset;
    boolean escaped = false;
    ByteStringBuilder buffer = new ByteStringBuilder();
    for(int i = start; i < length; i++)
    {
      if(dnKey[i] == 0x5C)
      {
        escaped = true;
        continue;
      }
      else if(!escaped && dnKey[i] == 0x01)
      {
        buffer.append(0x01);
        escaped = false;
        continue;
      }
      else if(!escaped && dnKey[i] == 0x00)
      {
        if(buffer.length() > 0)
        {
          dn = dn.concat(RDN.decode(buffer.toString()));
          buffer.clear();
        }
      }
      else
      {
        if(escaped)
        {
          buffer.append(0x5C);
          escaped = false;
        }
        buffer.append(dnKey[i]);
      }
    }

    if(buffer.length() > 0)
    {
      dn = dn.concat(RDN.decode(buffer.toString()));
    }

    return dn;
  }
View Full Code Here

    private static String newDn="cn=new dn, dc=example,dc=com";
    private static String creds="some creds";

  @Test()
  public void testBindRequestEncodeDecode() throws Exception {
    ByteStringBuilder simpleBuilder = new ByteStringBuilder();
    ASN1Writer simpleWriter = ASN1.getWriter(simpleBuilder);
    ByteStringBuilder saslBuilder = new ByteStringBuilder();
    ASN1Writer saslWriter = ASN1.getWriter(saslBuilder);
    ByteString bindDn=ByteString.valueOf(dn);
    ByteString pw=ByteString.valueOf(pwd);
    BindRequestProtocolOp simple =
      new BindRequestProtocolOp(bindDn, 3, pw);
    BindRequestProtocolOp sasl =
      new BindRequestProtocolOp(bindDn, SASL_MECHANISM_PLAIN, pw);
    simple.write(simpleWriter);
    sasl.write(saslWriter);
    // Decode to a new protocol op.
    ASN1Reader simpleReader = ASN1.getReader(simpleBuilder.toByteString());
    ASN1Reader saslReader = ASN1.getReader(saslBuilder.toByteString());
    ProtocolOp simpleDecodedOp = LDAPReader.readProtocolOp(simpleReader);
    ProtocolOp saslDecodedOp = LDAPReader.readProtocolOp(saslReader);
    assertTrue(saslDecodedOp instanceof BindRequestProtocolOp);
    assertTrue(simpleDecodedOp instanceof BindRequestProtocolOp);
    BindRequestProtocolOp simpleOp =
View Full Code Here

TOP

Related Classes of org.nasutekds.server.types.ByteStringBuilder$SubSequence

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.