directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ole Ersoy <ole.er...@gmail.com>
Subject Re: [DAS] Generating OIDs
Date Fri, 13 Apr 2007 23:13:00 GMT



Emmanuel Lecharny wrote:
SNIP

> This is not what I suggested. Did you read my mails carefully ?

Maybe :-)

> 
> I said that you should :
> - have unique OIDs
Yap
> - use the String structure to generate the oid
Yap
> - and to avoid insanely long oids, use a hascode of each part of the 
> string to generate an oid
Yap

> 
> Something like :
>    private static String getOid( String prefix, String param )
>    {
>        StringTokenizer tokens = new StringTokenizer( param, "." );
>        StringBuilder oid  = new StringBuilder( prefix );
>              while ( tokens.hasMoreElements() )
>        {
>            oid.append( '.' ).append( Math.abs( 
> tokens.nextElement().hashCode() ) );
>        }
>              return oid.toString();
>    }
> 
> When you call it with :
> getOid( "1.3.6.1.4.1.18060.0.4.100.2", 
> "org.apache.tuscany.das.ldap.DASConfig" )
> 
> you get this OID :
> 1.3.6.1.4.1.18060.0.4.100.2.110308.1411517106.964893765.99222.3316647.1638106712 
> 
> 
> where
> org -> 110308
> apache -> 1411517106
> tuscany -> 964893765
> das -> 99222
> ldap -> 3316647
> DASConfig -> 1638106712

Yes - We are doing the same thing, except I just added the
hashes and replaced "-" with "1" to get (I excluded the OID prefix part):

1103081141151710619648937659922233166471638106712

110308
11411517106
1964893765
99222
3316647
1638106712

org -> 110308
apache -> 1411517106
tuscany -> 964893765
das -> 99222
ldap -> 3316647
DASConfig -> 1638106712


> 
> Alex suggestion was more straight forward : simply compute a checksum 
> from the whome string, but keeping the result into an int ( values 
> longer than an int won't be accepted by the server). In fact, more or 
> les a hashcode of the string (absolute value of the hashcode to avoid 
> negative number).

Here's (I think) a version of Alex's:

public static String generateUnqiueOIDPostfix(
     String namespacedMetadata)
throws NoSuchAlgorithmException
{
     MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");

     byte[] digest             = 
messageDigest.digest(namespacedMetadata.getBytes());

     StringBuffer hexString = new StringBuffer();
     for (int i=0;i<digest.length;i++) {
       hexString.append (
         Integer.toHexString(0xFF & digest[i]));
     }

     char[] hexStringCharacters = hexString.toString().toCharArray();
     String postfixOID = "";

     for( char i : hexStringCharacters)
     {
         int ascii = (int) i;
         postfixOID = postfixOID + Integer.toString(ascii);
     }
     return postfixOID;
}

Which if it is run like this:
String namespacedMetadata      = "org.apache.tuscany.das.ldap.DASConfig";
String output = generateUnqiueOIDPostfix( namespacedMetadata );
System.out.println (output);

Results in an ID like this:

56102575750102541005410297101555310155501025110051995255971009956102975452499754981015650


> Keep it simple, buddy !

You like?

Thanks and have a great weekend Emmanuel
(You should be sipping on a nice glass of wine right now btw,
instead of answering my mails :-) )

- Ole


,

> 
> Emmanuel
> 
> 

Mime
View raw message