#include <security_cdsa_utilities/acl_password.h>
#include <security_utilities/debugging.h>
#include <security_utilities/endian.h>
#include <algorithm>
bool PasswordAclSubject::getSecret(const AclValidationContext &context,
const TypedList &sample, CssmOwnedData &secret) const
{
switch (sample.length()) {
case 1:
return false; case 2:
secret = sample[1];
return true;
default:
CssmError::throwMe(CSSM_ERRCODE_INVALID_SAMPLE_VALUE);
}
}
CssmList PasswordAclSubject::toList(Allocator &alloc) const
{
return TypedList(alloc, CSSM_ACL_SUBJECT_TYPE_PASSWORD);
}
PasswordAclSubject *PasswordAclSubject::Maker::make(const TypedList &list) const
{
Allocator &alloc = Allocator::standard(Allocator::sensitive);
switch (list.length()) {
case 1:
return new PasswordAclSubject(alloc, true);
case 2:
{
ListElement *password;
crack(list, 1, &password, CSSM_LIST_ELEMENT_DATUM);
return new PasswordAclSubject(alloc, password->data());
}
default:
CssmError::throwMe(CSSM_ERRCODE_INVALID_ACL_SUBJECT_VALUE);
}
}
PasswordAclSubject *PasswordAclSubject::Maker::make(Version, Reader &pub, Reader &priv) const
{
Allocator &alloc = Allocator::standard(Allocator::sensitive);
const void *data; size_t length; priv.countedData(data, length);
CssmAutoData passwordData(alloc, data, length);
return new PasswordAclSubject(alloc, passwordData);
}
void PasswordAclSubject::exportBlob(Writer::Counter &pub, Writer::Counter &priv)
{
priv.countedData(secret());
}
void PasswordAclSubject::exportBlob(Writer &pub, Writer &priv)
{
priv.countedData(secret());
}
#ifdef DEBUGDUMP
void PasswordAclSubject::debugDump() const
{
Debug::dump("Password");
SecretAclSubject::debugDump();
}
#endif //DEBUGDUMP