Certified GKH Gardening Expert
Although they would be safe for cooking, they may not taste as they would have! This sounds like a fungal infection, which is most common with over-watering. Make sure to let it dry out pretty well between waterings, if possible.
Alternatively, if you live in a colder region, than this is likely the cause. Again, it won't be any harm to you, but they may not taste their best.
If you find that you do not want to eat them, you can boil them in water, and use this as a mild insecticide.
Here is an article for further care of rosemary: https://www.gardeningknowhow.com/edible/herbs/rosemary/growing-rosemary-plants-rosemary-plant-care.htm