You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Ole Ersoy <ol...@gmail.com> on 2007/04/14 00:07:22 UTC

[DAS] Generating OIDs

Hey Guys,

I've been experimenting with Alex's (Checksum) and Emmanuel's (Hashcode)
OID generation suggestions.

One way to do it would be to generate a SHA-1 digest.

So for:
org.apache.tuscany.das.ldap.DASConfig

We would get:
8f992f6d6fae75e72f3d3c47adc8fa641a6be82

Then we could just replace the letters with a corresponding
integer.

Does anyone know whether this will always produce alphabetical letters
numbers though?

The code I have creates the checksum like this:

MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
String checksumInput      = "org.apache.tuscany.das.ldap.DASConfig";
byte[] digest             = messageDigest.digest(checksumInput.getBytes());

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


Then there's Emmanuel's way which works like this:

String[] test = "org.apache.tuscany.das.ldap.DASConfig".split( "[.]" );
String final  = "";
for (int i=0;i<test.length;i++)
{
    String hash = StringUtils.replace(test[i], "-", "1");
    //We replace "-" with "1".
    final = final + hash;
}

This will give the id:

1103081141151710619648937659922233166471638106712

I'd probably go with this one since it's simpler to just replace
a "-" than letters...

Thoughts?

Thanks,
- Ole









Re: [DAS] Generating OIDs

Posted by Ole Ersoy <ol...@gmail.com>.
OK - Cooolll!!

I'll make sure I chop it into pieces smaller than
Integer.MAX_INT

Thanks,
- Ole

"The Amigos - WE GOT IT!!!"

Re: [DAS] Generating OIDs

Posted by Emmanuel Lecharny <el...@gmail.com>.
> 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

This is not good. An OID should not contain numbers longer that 
Integer.MAX_INT. This is a clear limitation of the server, but you have 
to live with.
<Snip/>

> 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 :-) )

Yeah, I know, but it's 1:30 am here in Paris... Enjoy your week-end too !

Emmanuel


Re: [DAS] Generating OIDs

Posted by Ole Ersoy <ol...@gmail.com>.


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
> 
> 

Re: [DAS] Generating OIDs

Posted by Emmanuel Lecharny <el...@gmail.com>.
Ole Ersoy a écrit :

> Hey Guys,
>
> I've been experimenting with Alex's (Checksum) and Emmanuel's (Hashcode)
> OID generation suggestions.
> <snip>
> Then there's Emmanuel's way which works like this:
>
> String[] test = "org.apache.tuscany.das.ldap.DASConfig".split( "[.]" );
> String final  = "";
> for (int i=0;i<test.length;i++)
> {
>    String hash = StringUtils.replace(test[i], "-", "1");
>    //We replace "-" with "1".
>    final = final + hash;
> }
>
> This will give the id:
>
> 1103081141151710619648937659922233166471638106712
>
> I'd probably go with this one since it's simpler to just replace
> a "-" than letters...
>
> Thoughts?

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

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

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

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).

Keep it simple, buddy !

Emmanuel