1. A person who goes armed with, carries, or transports a firearm of any kind, whether concealed or not, on the grounds of a school commits a class “D” felony. For the purposes of this section, “school” means a public or nonpublic school as defined in section 280.2.
 2. Subsection 1 does not apply to the following:

 a. A person who has been specifically authorized by the school to go armed with, carry, or transport a firearm on the school grounds for any lawful purpose.
 b. A peace officer including a peace officer who has not been certified and a federal officer when the officer’s employment requires going armed, whether or not the peace officer or federal officer is acting in the performance of official duties.
 c. A member of the armed forces of the United States or of the national guard or person in the service of the United States, when the firearm is carried in connection with the person’s duties as such.
 d. A correctional officer, when the officer’s duties require the officer to carry a firearm, serving under the authority of the Iowa department of corrections.
 e. A person who for any lawful purpose carries an unloaded pistol, revolver, or other firearm inside a closed and fastened container or securely wrapped package that is too large to be concealed on the person.
 f. A person who for any lawful purpose carries or transports an unloaded pistol, revolver, or other firearm in a vehicle or common carrier inside a closed and fastened container or securely wrapped package that is too large to be concealed on the person or carries or transports an unloaded pistol, revolver, or other firearm inside a cargo or luggage compartment where the pistol or revolver will not be readily accessible to any person riding in the vehicle or common carrier.
 g. A law enforcement officer from another state when the officer’s duties require the officer to carry a firearm and the officer is in this state for any of the following reasons:

 (1) The extradition or other lawful removal of a prisoner from this state.
 (2) Pursuit of a suspect in compliance with chapter 806.
 (3) Activities in the capacity of a law enforcement officer with the knowledge and consent of the chief of police of the city or the sheriff of the county in which the activities occur or of the commissioner of public safety.
 h. A licensee under chapter 80A or an employee of such a licensee, while the licensee or employee is engaged in the performance of duties, and if the licensee or employee possesses a valid professional or nonprofessional permit to carry weapons issued pursuant to this chapter.