constify mad related functions when applicable.

This commit is contained in:
Romuald Conty 2010-07-20 07:47:58 +00:00
parent 2668b48232
commit cae581eded
2 changed files with 20 additions and 20 deletions

View file

@ -133,24 +133,24 @@ typedef struct mad *Mad;
/* MAD Public read key A */ /* MAD Public read key A */
extern const MifareClassicKey mad_public_key_a; extern const MifareClassicKey mad_public_key_a;
Mad mad_new (uint8_t version); Mad mad_new (const uint8_t version);
Mad mad_read (MifareTag tag); Mad mad_read (MifareTag tag);
int mad_write (MifareTag tag, Mad mad, MifareClassicKey key_b_sector_00, MifareClassicKey key_b_sector_10); int mad_write (MifareTag tag, Mad mad, const MifareClassicKey key_b_sector_00, const MifareClassicKey key_b_sector_10);
int mad_get_version (Mad mad); int mad_get_version (Mad mad);
void mad_set_version (Mad mad, uint8_t version); void mad_set_version (Mad mad, const uint8_t version);
MifareClassicSectorNumber mad_get_card_publisher_sector (Mad mad); MifareClassicSectorNumber mad_get_card_publisher_sector (Mad mad);
int mad_set_card_publisher_sector (Mad mad, MifareClassicSectorNumber cps); int mad_set_card_publisher_sector (Mad mad, const MifareClassicSectorNumber cps);
int mad_get_aid (Mad mad, MifareClassicSectorNumber sector, MadAid *aid); int mad_get_aid (Mad mad, const MifareClassicSectorNumber sector, MadAid *aid);
int mad_set_aid (Mad mad, MifareClassicSectorNumber sector, MadAid aid); int mad_set_aid (Mad mad, const MifareClassicSectorNumber sector, MadAid aid);
bool mad_sector_reserved (MifareClassicSectorNumber sector); bool mad_sector_reserved (const MifareClassicSectorNumber sector);
void mad_free (Mad mad); void mad_free (Mad mad);
ssize_t mad_application_read (MifareTag tag, Mad mad, MadAid aid, void *buf, size_t nbytes, MifareClassicKey key, MifareClassicKeyType key_type); ssize_t mad_application_read (MifareTag tag, Mad mad, const MadAid aid, void *buf, size_t nbytes, const MifareClassicKey key, const MifareClassicKeyType key_type);
ssize_t mad_application_write (MifareTag tag, Mad mad, MadAid aid, const void *buf, size_t nbytes, MifareClassicKey key, MifareClassicKeyType key_type); ssize_t mad_application_write (MifareTag tag, Mad mad, const MadAid aid, const void *buf, size_t nbytes, const MifareClassicKey key, const MifareClassicKeyType key_type);
MifareClassicSectorNumber *mifare_application_alloc (Mad mad, MadAid aid, size_t size); MifareClassicSectorNumber *mifare_application_alloc (Mad mad, const MadAid aid, const size_t size);
void mifare_application_free (Mad mad, MadAid aid); void mifare_application_free (Mad mad, const MadAid aid);
MifareClassicSectorNumber *mifare_application_find (Mad mad, MadAid aid); MifareClassicSectorNumber *mifare_application_find (Mad mad, const MadAid aid);
uint8_t *tlv_encode (const uint8_t type, const uint8_t *istream, uint16_t isize, size_t *osize); uint8_t *tlv_encode (const uint8_t type, const uint8_t *istream, uint16_t isize, size_t *osize);

View file

@ -241,7 +241,7 @@ error:
* Write the mad to the provided MIFARE tad using the provided Key-B keys. * Write the mad to the provided MIFARE tad using the provided Key-B keys.
*/ */
int int
mad_write (MifareTag tag, Mad mad, MifareClassicKey key_b_sector_00, MifareClassicKey key_b_sector_10) mad_write (MifareTag tag, Mad mad, const MifareClassicKey key_b_sector_00, const MifareClassicKey key_b_sector_10)
{ {
MifareClassicBlock data; MifareClassicBlock data;
@ -327,7 +327,7 @@ mad_get_version (Mad mad)
* Set a MAD version. * Set a MAD version.
*/ */
void void
mad_set_version (Mad mad, uint8_t version) mad_set_version (Mad mad, const uint8_t version)
{ {
if ((version == 2) && (mad->version == 1)) { if ((version == 2) && (mad->version == 1)) {
/* We use a larger MAD so initialise the new blocks */ /* We use a larger MAD so initialise the new blocks */
@ -349,7 +349,7 @@ mad_get_card_publisher_sector(Mad mad)
* Set the MAD card publisher sector. * Set the MAD card publisher sector.
*/ */
int int
mad_set_card_publisher_sector(Mad mad, MifareClassicSectorNumber cps) mad_set_card_publisher_sector(Mad mad, const MifareClassicSectorNumber cps)
{ {
if (((mad->version == 2) && (cps > 0x27)) | (mad->version == 1) && (cps > 0x0f)) { if (((mad->version == 2) && (cps > 0x27)) | (mad->version == 1) && (cps > 0x0f)) {
errno = EINVAL; errno = EINVAL;
@ -364,7 +364,7 @@ mad_set_card_publisher_sector(Mad mad, MifareClassicSectorNumber cps)
* Get the provided sector's application identifier. * Get the provided sector's application identifier.
*/ */
int int
mad_get_aid(Mad mad, MifareClassicSectorNumber sector, MadAid *aid) mad_get_aid(Mad mad, const MifareClassicSectorNumber sector, MadAid *aid)
{ {
if ((sector < 1) || (sector == 0x10) || (sector > 0x27)) { if ((sector < 1) || (sector == 0x10) || (sector > 0x27)) {
errno = EINVAL; errno = EINVAL;
@ -391,7 +391,7 @@ mad_get_aid(Mad mad, MifareClassicSectorNumber sector, MadAid *aid)
* Set the provided sector's application identifier. * Set the provided sector's application identifier.
*/ */
int int
mad_set_aid(Mad mad, MifareClassicSectorNumber sector, MadAid aid) mad_set_aid(Mad mad, const MifareClassicSectorNumber sector, MadAid aid)
{ {
if ((sector < 1) || (sector == 0x10) || (sector > 0x27)) { if ((sector < 1) || (sector == 0x10) || (sector > 0x27)) {
errno = EINVAL; errno = EINVAL;
@ -414,7 +414,7 @@ mad_set_aid(Mad mad, MifareClassicSectorNumber sector, MadAid aid)
} }
bool bool
mad_sector_reserved (MifareClassicSectorNumber sector) mad_sector_reserved (const MifareClassicSectorNumber sector)
{ {
return ((0x00 == sector) || (0x10 == sector)); return ((0x00 == sector) || (0x10 == sector));
} }
@ -429,7 +429,7 @@ mad_free (Mad mad)
} }
ssize_t ssize_t
mad_application_read (MifareTag tag, Mad mad, MadAid aid, void *buf, size_t nbytes, MifareClassicKey key, MifareClassicKeyType key_type) mad_application_read (MifareTag tag, Mad mad, const MadAid aid, void *buf, size_t nbytes, const MifareClassicKey key, const MifareClassicKeyType key_type)
{ {
ssize_t res = 0; ssize_t res = 0;
@ -474,7 +474,7 @@ mad_application_read (MifareTag tag, Mad mad, MadAid aid, void *buf, size_t nbyt
} }
ssize_t ssize_t
mad_application_write (MifareTag tag, Mad mad, MadAid aid, const void *buf, size_t nbytes, MifareClassicKey key, MifareClassicKeyType key_type) mad_application_write (MifareTag tag, Mad mad, const MadAid aid, const void *buf, size_t nbytes, const MifareClassicKey key, const MifareClassicKeyType key_type)
{ {
ssize_t res = 0; ssize_t res = 0;