#ifndef HELLO_H #define HELLO_H #include #include #include "buffer.h" static const uint8_t METHOD_NO_AUTHENTICATION_REQUIRED = 0x00; static const uint8_t METHOD_USERNAME_PASSWORD_AUTHENTICATION = 0x02; static const uint8_t METHOD_NO_ACCEPTABLE_METHODS = 0xFF; enum hello_state { hello_version, hello_nmethods, hello_methods, hello_done, hello_error_unsupported_version, }; struct hello_parser { void (* on_authentication_method) (struct hello_parser * parser, const uint8_t method); void * data; enum hello_state state; uint8_t remaining; uint8_t has_selected; }; void hello_parser_init(struct hello_parser *p); enum hello_state hello_parser_feed(struct hello_parser * p, uint8_t b); enum hello_state hello_consume(buffer * b, struct hello_parser * p, bool * errored); bool hello_is_done(enum hello_state state, bool * errored); extern const char * hello_error(const struct hello_parser *p); void hello_parser_close(struct hello_parser *p); extern int hello_marshall(buffer * b, uint8_t method); #endif