/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* * XXX This should be rewritten, generalized, to take a long instead * of a PRInt32.
*/
SECStatus
DER_SetInteger(PLArenaPool *arena, SECItem *it, PRInt32 i)
{ unsignedchar bb[4]; unsigned len;
/* ** Small integers are encoded in a single byte. Larger integers ** require progressively more space.
*/ if (i < -128) { if (i < -32768L) { if (i < -8388608L) {
len = 4;
} else {
len = 3;
}
} else {
len = 2;
}
} elseif (i > 127) { if (i > 32767L) { if (i > 8388607L) {
len = 4;
} else {
len = 3;
}
} else {
len = 2;
}
} else {
len = 1;
}
it->data = (unsignedchar *)PORT_ArenaAlloc(arena, len); if (!it->data) { return SECFailure;
}
it->len = len;
PORT_Memcpy(it->data, bb + (4 - len), len); return SECSuccess;
}
/* * XXX This should be rewritten, generalized, to take an unsigned long instead * of a PRUint32.
*/
SECStatus
DER_SetUInteger(PLArenaPool *arena, SECItem *it, PRUint32 ui)
{ unsignedchar bb[5]; int len;
/* ** Small integers are encoded in a single byte. Larger integers ** require progressively more space.
*/ if (ui > 0x7f) { if (ui > 0x7fff) { if (ui > 0x7fffffL) { if (ui >= 0x80000000L) {
len = 5;
} else {
len = 4;
}
} else {
len = 3;
}
} else {
len = 2;
}
} else {
len = 1;
}
/* ** Convert a der encoded *signed* integer into a machine integral value. ** If an underflow/overflow occurs, sets error code and returns min/max.
*/ long
DER_GetInteger(const SECItem *it)
{ unsignedlong ival;
PRBool negative; unsignedint len = it->len; unsignedchar *cp = it->data;
size_t lsize = sizeof(ival);
PORT_Assert(len); if (!len) {
PORT_SetError(SEC_ERROR_INPUT_LEN); return 0;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.