+
+int pb_protocol_deserialise_authenticate(struct auth_message *msg,
+ const struct pb_protocol_message *message)
+{
+ unsigned int len;
+ const char *pos;
+
+ len = message->payload_len;
+ pos = message->payload;
+
+ msg->op = *(enum auth_msg_type *)pos;
+ pos += sizeof(enum auth_msg_type);
+
+ switch (msg->op) {
+ case AUTH_MSG_REQUEST:
+ if (read_string(msg, &pos, &len, &msg->password))
+ return -1;
+ break;
+ case AUTH_MSG_RESPONSE:
+ msg->authenticated = *(bool *)pos;
+ pos += sizeof(bool);
+ break;
+ case AUTH_MSG_SET:
+ if (read_string(msg, &pos, &len, &msg->set_password.password))
+ return -1;
+ if (read_string(msg, &pos, &len,
+ &msg->set_password.new_password))
+ return -1;
+ break;
+ default:
+ pb_log("%s: unable to parse\n", __func__);
+ return -1;
+ }
+
+ return 0;
+}