示例#1
0
 void basis_req_parcel::value(const short_value& vl) {
     if (is_bcd()) {
         short_value tmp = vl;
         tmp.covert_to_bcd();
         value_ = tmp;
         isvalue_ = !tmp.error();
         return;
     } else {
         value_ = vl;
         isvalue_ = !vl.error();
     }
 }
示例#2
0
static int
cvc_check_time(const CVC_CERT *cert)
{
    time_t loc;
    struct tm exp_tm, eff_tm, *utc_tm;

    if (!cert || !cert->body
            || !cert->body->certificate_effective_date
            || cert->body->certificate_effective_date->length != 6
            || !is_bcd(cert->body->certificate_effective_date->data,
                cert->body->certificate_effective_date->length)
            || cert->body->certificate_expiration_date->length != 6
            || !is_bcd(cert->body->certificate_expiration_date->data,
                cert->body->certificate_expiration_date->length))
        return -1;

    /* FIXME gmtime is not thread safe */
    time(&loc);
    utc_tm = gmtime(&loc);
    if (!utc_tm)
        return -1;

    memcpy(&eff_tm, utc_tm, sizeof(struct tm));
    eff_tm.tm_sec = 0;          /* seconds */
    eff_tm.tm_min = 0;          /* minutes */
    eff_tm.tm_hour = 0;         /* hours */
    eff_tm.tm_wday = -1;        /* day of the week */
    eff_tm.tm_yday = -1;        /* day in the year */
    eff_tm.tm_year = 100        /* The number of years since 1900 */
        + ((unsigned char) cert->body->certificate_effective_date->data[0])*10
        + (unsigned char) cert->body->certificate_effective_date->data[1];
    eff_tm.tm_mon = ((unsigned char) cert->body->certificate_effective_date->data[2])*10
        + (unsigned char) cert->body->certificate_effective_date->data[3] - 1;
    eff_tm.tm_mday = ((unsigned char) cert->body->certificate_effective_date->data[4])*10
        + (unsigned char) cert->body->certificate_effective_date->data[5];

    memcpy(&exp_tm, utc_tm, sizeof(struct tm));
    exp_tm.tm_sec = 59;         /* seconds */
    exp_tm.tm_min = 59;         /* minutes */
    exp_tm.tm_hour = 23;        /* hours */
    exp_tm.tm_wday = -1;        /* day of the week */
    exp_tm.tm_yday = -1;        /* day in the year */
    exp_tm.tm_year = 100        /* The number of years since 1900 */
        + ((unsigned char) cert->body->certificate_expiration_date->data[0])*10
        + (unsigned char) cert->body->certificate_expiration_date->data[1];
    exp_tm.tm_mon = ((unsigned char) cert->body->certificate_expiration_date->data[2])*10
        + (unsigned char) cert->body->certificate_expiration_date->data[3] - 1;
    exp_tm.tm_mday = ((unsigned char) cert->body->certificate_expiration_date->data[4])*10
        + (unsigned char) cert->body->certificate_expiration_date->data[5];

    if (exp_tm.tm_mon < 0 || exp_tm.tm_mon > 12
            || exp_tm.tm_mday > 31
            || eff_tm.tm_mon < 0 || eff_tm.tm_mon > 11
            || eff_tm.tm_mday > 31
            || difftime(mktime(utc_tm), mktime(&eff_tm)) < 0
            || difftime(mktime(&exp_tm), mktime(utc_tm)) < 0) {
        return 0;
    }

    return 1;
}