Hi Martin,

On Tuesday 07 August 2001 12:06, you wrote:
> Is there a way to get out the 'timestamp' from an ASN1_TIME structure so I
> can compare it with other times? Yes I know there are _cmp functions but I
> want to be able to use < and >...
>
> Martin

I'm writing some Python wrappers at the moment and hade to do the same thing 
on several occations and used a helper to get a time in seconds...

PyObject *
helper_get_date (ASN1_UTCTIME *time)
{
   int seconds=0, local_hour=0, local_minute=0, local_seconds=0;
   char buf[16];
   struct tm cert_time;

   memcpy( buf, time->data, 12 );
   strptime( buf, "%y%m%d%H%M%S", &cert_time );
   seconds = mktime( &cert_time );

   memcpy( buf, &time->data[13], 2 ); // get hour value
   buf[2] = 0; local_hour = atoi(buf); 
   memcpy( buf, &time->data[16], 2 ); // get minute value
   buf[2] = 0; local_minute = atoi(buf); 

   local_seconds = (local_hour * 60 * 60) + (local_minute * 60);
   if (time->data[12] == '-')
      local_seconds *= -1;

   return Py_BuildValue("(ii)", seconds, local_seconds);

error:

   return NULL;
}

Obvioustly you want to ignore the return type, seconds is what you would 
really be interested in.  The local seconds are the time zone offset.

Hope this helps, also hope I didn't miss any built in functions which do the 
same thing. 

Peter Shannon.
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to