📄 emailencode.c
字号:
if (attrListV1 != (Asn1AttributeListV1 *)0)
Asn1AttributeListV1_free (attrListV1);
if (emailValueV2 != (Asn1EmailValueV2 *)0)
Asn1EmailValueV2_free (emailValueV2);
if (status == 0)
return (0);
if (buffer != (unsigned char *)0)
Z2Free (buffer);
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, idObj, status, 0, errorType,
(char *)0, "EncodeSchemaEmailAlloc", fnctLine, (char *)0)
return (status);
}
static int DetermineOffset (
VtLibCtx libraryCtx,
unsigned char *emailAddress,
unsigned int emailAddressLen,
unsigned int validityPeriod,
unsigned int segmentCount,
UInt32 *offset
)
{
int status;
unsigned int value;
VtAlgorithmObject sha1 = (VtAlgorithmObject)0;
unsigned char digest[20];
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* Digest the email address. The offset is the digest mod 7.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCreateAlgorithmObject (
libraryCtx, VtAlgorithmImplSHA1, (Pointer)0, &sha1);
if (status != 0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VtDigestInit (sha1);
if (status != 0)
break;
/* Use value as a temp variable.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VtDigestFinal (
sha1, emailAddress, emailAddressLen, digest, 20, &value);
if (status != 0)
break;
value = (unsigned int)digest[0];
value %= segmentCount;
*offset = (UInt32)(value * (validityPeriod / segmentCount));
} while (0);
VtDestroyAlgorithmObject (&sha1);
VOLT_LOG_ERROR_INFO_COMPARE (
status, libraryCtx, 0, status, 0, 0,
(char *)0, "DetermineOffset", fnctLine, (char *)0)
return (status);
}
int VtIdentitySchemaDecode822Email (
VtIdentityObject idObj,
Asn1Identity *ident,
unsigned int flag
)
{
int status;
unsigned int version;
VoltIdentityObject *obj = (VoltIdentityObject *)idObj;
VoltLibCtx *libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
Asn1ObjectId *oid;
Asn1AttributeListV1 *v1Attrs = (Asn1AttributeListV1 *)0;
Asn1SchemaV2 *v2Schema = (Asn1SchemaV2 *)0;
Asn1EmailValueV2 *emailValue = (Asn1EmailValueV2 *)0;
unsigned char *temp;
unsigned char *emailCopy = (char *)0;
unsigned char mailOid[VoltIdSchemaOid822EmailLen] =
{ VoltIdSchemaOid822Email };
VtEmailInfo emailInfo;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
Z2Memset (&emailInfo, 0, sizeof (VtEmailInfo));
do
{
/* Check the flag, it should be VOLT_DECODER_TYPE_FLAG.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_DECODER_TYPE_FLAG)
break;
/* Which version?
*/
version = VT_ENCODE_IBCS_2_V_1;
if (ident->version != (ASN1_INTEGER *)0)
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ENCODING;
if (ident->version->length != 1)
break;
if (ident->version->data[0] != 2)
break;
version = VT_ENCODE_IBCS_2_V_2;
}
if (version == VT_ENCODE_IBCS_2_V_1)
{
/* If version 1, look for the profiles
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ENCODING;
if (ident->profiles == (STACK *)0)
break;
/* We expect to see 1 entry.
*/
VOLT_SET_FNCT_LINE (fnctLine)
if (ident->profiles->num != 1)
break;
/* That entry should be 822mail.
*/
VOLT_SET_FNCT_LINE (fnctLine)
oid = (Asn1ObjectId *)(ident->profiles->data[0]);
if (oid->base.length != VoltIdSchemaOid822EmailLen)
break;
if (Z2Memcmp (
oid->base.data, mailOid, VoltIdSchemaOid822EmailLen) != 0)
break;
/* Decode the attribute.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
v1Attrs = Asn1AttributeListV1_new ();
if (v1Attrs == (Asn1AttributeListV1 *)0)
break;
/* Decode the attributes.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ENCODING;
temp = ident->schema->base.data;
d2i_Asn1AttributeListV1 (&v1Attrs, &temp, ident->schema->base.length);
if (v1Attrs == (Asn1AttributeListV1 *)0)
break;
/* Make sure the id's are correct.
*/
VOLT_SET_FNCT_LINE (fnctLine)
if (v1Attrs->notBefore->id->length != NotBeforeKeyStringLen)
break;
if (Z2Memcmp (
v1Attrs->notBefore->id->data, NotBeforeKeyString,
NotBeforeKeyStringLen) != 0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
if (v1Attrs->email->id->length != EmailKeyStringLen)
break;
if (Z2Memcmp (
v1Attrs->email->id->data, EmailKeyString, EmailKeyStringLen) != 0)
break;
/* Build the emailInfo struct
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
emailCopy = (unsigned char *)Z2Malloc (
v1Attrs->email->value->length + 1, 0);
if (emailCopy == (unsigned char *)0)
break;
Z2Memcpy (
emailCopy, v1Attrs->email->value->data, v1Attrs->email->value->length);
emailCopy[v1Attrs->email->value->length] = 0;
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
emailInfo.emailAddress = emailCopy;
status = VoltConvertUTCToVtTime (
libCtx, v1Attrs->notBefore->value->data, &(emailInfo.emailTime));
if (status != 0)
break;
}
else
{
/* If version 2, make sure there are no profiles.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ENCODING;
if (ident->profiles != (STACK *)0)
break;
/* Decode the schema into OID and value.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
v2Schema = Asn1SchemaV2_new ();
if (v2Schema == (Asn1SchemaV2 *)0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ENCODING;
temp = ident->schema->base.data;
d2i_Asn1SchemaV2 (&v2Schema, &temp, ident->schema->base.length);
if (v2Schema == (Asn1SchemaV2 *)0)
break;
/* Make sure this is the 822 mail OID.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_UNKNOWN_SCHEMA;
oid = v2Schema->oid;
if (oid->base.length != VoltIdSchemaOid822EmailLen)
break;
if (Z2Memcmp (
oid->base.data, mailOid, VoltIdSchemaOid822EmailLen) != 0)
break;
/* This is email, decode the value.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
emailValue = Asn1EmailValueV2_new ();
if (emailValue == (Asn1EmailValueV2 *)0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ENCODING;
temp = v2Schema->value->data;
d2i_Asn1EmailValueV2 (&emailValue, &temp, v2Schema->value->length);
if (emailValue == (Asn1EmailValueV2 *)0)
break;
/* It decoded, build the emailInfo struct.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
emailCopy = (unsigned char *)Z2Malloc (
emailValue->address->length + 1, 0);
if (emailCopy == (unsigned char *)0)
break;
Z2Memcpy (
emailCopy, emailValue->address->data, emailValue->address->length);
emailCopy[emailValue->address->length] = 0;
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
emailInfo.emailAddress = emailCopy;
status = VoltConvertGenTimeToVtTime (
libCtx, emailValue->notBefore->data, emailValue->notBefore->length,
&(emailInfo.emailTime));
if (status != 0)
break;
}
VOLT_SET_FNCT_LINE (fnctLine)
status = VtSetIdentityParam (
(VtIdentityObject)obj, VtIdentityParam822Email, (Pointer)&emailInfo);
if (status != 0)
break;
/* If this all works, copy values into the object.
*/
idObj->schema->idTime = emailInfo.emailTime;
idObj->encodingVersion = version;
} while (0);
if (emailCopy != (unsigned char *)0)
Z2Free (emailCopy);
if (v1Attrs != (Asn1AttributeListV1 *)0)
Asn1AttributeListV1_free (v1Attrs);
if (v2Schema != (Asn1SchemaV2 *)0)
Asn1SchemaV2_free (v2Schema);
if (emailValue != (Asn1EmailValueV2 *)0)
Asn1EmailValueV2_free (emailValue);
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, idObj, status, 0, errorType,
(char *)0, "VtIdentitySchemaDecode822Email", fnctLine, (char *)0)
return (status);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -