# Module `0x1::acl`
Access control list (ACL) module. An ACL is a list of account addresses who
have the access permission to a certain object.
This module uses a vector
to represent the list, but can be refactored to
use a "set" instead when it's available in the language in the future.
- [Struct `ACL`](#0x1_acl_ACL)
- [Constants](#@Constants_0)
- [Function `empty`](#0x1_acl_empty)
- [Function `add`](#0x1_acl_add)
- [Function `remove`](#0x1_acl_remove)
- [Function `contains`](#0x1_acl_contains)
- [Function `assert_contains`](#0x1_acl_assert_contains)
use 0x1::errors;
use 0x1::vector;
## Struct `ACL`
struct ACL has copy, drop, store
Fields
-
list: vector<address>
-
## Constants
The ACL already contains the address.
const ECONTAIN: u64 = 0;
The ACL does not contain the address.
const ENOT_CONTAIN: u64 = 1;
## Function `empty`
Return an empty ACL.
public fun empty(): acl::ACL
Implementation
public fun empty(): ACL {
ACL{ list: vector::empty<address>() }
}
## Function `add`
Add the address to the ACL.
public fun add(acl: &mut acl::ACL, addr: address)
Implementation
public fun add(acl: &mut ACL, addr: address) {
assert!(!vector::contains(&mut acl.list, &addr), errors::invalid_argument(ECONTAIN));
vector::push_back(&mut acl.list, addr);
}
## Function `remove`
Remove the address from the ACL.
public fun remove(acl: &mut acl::ACL, addr: address)
Implementation
public fun remove(acl: &mut ACL, addr: address) {
let (found, index) = vector::index_of(&mut acl.list, &addr);
assert!(found, errors::invalid_argument(ENOT_CONTAIN));
vector::remove(&mut acl.list, index);
}
## Function `contains`
Return true iff the ACL contains the address.
public fun contains(acl: &acl::ACL, addr: address): bool
Implementation
public fun contains(acl: &ACL, addr: address): bool {
vector::contains(&acl.list, &addr)
}
## Function `assert_contains`
assert! that the ACL has the address.
public fun assert_contains(acl: &acl::ACL, addr: address)
Implementation
public fun assert_contains(acl: &ACL, addr: address) {
assert!(contains(acl, addr), errors::invalid_argument(ENOT_CONTAIN));
}